コード例 #1
0
# a boolean that indicates if it was a double tap.  You might see both a single
# and double tap!
def tap_data(single, double):
    if single:
        print('Single click!')
    if double:
        print('Double click!')


# Stream tap data for 2 seconds, then pause for 5 seconds and stream forever.
print('Streaming tap data for 2 seconds...')
board.start_tap(tap_data)
time.sleep(2.0)

print('Pausing for 5 seconds...')
board.stop_tap()
time.sleep(5.0)

try:
    # Wait in a loop to receive tap data from the board in the background.
    print('Printing tap data (Ctrl-C to quit)...')
    board.start_tap(tap_data)
    while True:
        time.sleep(1.0)
finally:
    print('Stopping!')
    board.stop_tap()

# Close Firmata board connection when done.
board.close()
コード例 #2
0
# a boolean that indicates if it was a single tap, and the double parameter is
# a boolean that indicates if it was a double tap.  You might see both a single
# and double tap!
def tap_data(single, double):
    if single:
        print('Single click!')
    if double:
        print('Double click!')

# Stream tap data for 2 seconds, then pause for 5 seconds and stream forever.
print('Streaming tap data for 2 seconds...')
board.start_tap(tap_data)
time.sleep(2.0)

print('Pausing for 5 seconds...')
board.stop_tap()
time.sleep(5.0)

try:
    # Wait in a loop to receive tap data from the board in the background.
    print('Printing tap data (Ctrl-C to quit)...')
    board.start_tap(tap_data)
    while True:
        time.sleep(1.0)
finally:
    print('Stopping!')
    board.stop_tap()

# Close Firmata board connection when done.
board.close()