コード例 #1
0
firmata.set_pin_mode(BUTTON_SWITCH, firmata.INPUT, firmata.DIGITAL)

# Arm pin A2 for latching a value >= 678
firmata.set_analog_latch(POTENTIOMETER, firmata.ANALOG_LATCH_GTE, 678)

# Arm pin 12 for latching when the pin goes high
firmata.set_digital_latch(BUTTON_SWITCH, firmata.DIGITAL_LATCH_HIGH)

print "start waiting"
# wait for 5 seconds to allow user interaction with switch and pot
# during this time press and release the switch and turn the pot to maximum

time.sleep(5)

print 'end waiting'
# get and print the digital latched data
print firmata.get_digital_latch_data(BUTTON_SWITCH)

# get and print the analog data latched data
a_latch = firmata.get_analog_latch_data(POTENTIOMETER)
print a_latch
# print gmtime for the time stamp
print time.gmtime(a_latch[firmata.LATCHED_TIME_STAMP])

# wait 2 more seconds and see that the latch entry data is now cleared

time.sleep(2)
print firmata.get_digital_latch_data(BUTTON_SWITCH)
print firmata.get_analog_latch_data(POTENTIOMETER)

firmata.close()
コード例 #2
0
signal.signal(signal.SIGINT, signal_handler)

# Set digital pin 13 to be an output port
board.set_pin_mode(BOARD_LED, board.OUTPUT, board.DIGITAL)
board.enable_digital_reporting(BOARD_LED)
time.sleep(2)
print("Blinking LED on pin 13 for 10 times ...")

# Blink for 10 times
for x in range(10):
    print(x + 1)
    # Set the output to 1 = High
    board.digital_write(BOARD_LED, 1)
    board.set_digital_latch(BOARD_LED, board.DIGITAL_LATCH_HIGH)
    board.pin_state_query(BOARD_LED)
    # Wait a half second between toggles.
    time.sleep(.5)
    l = board.get_digital_latch_data(BOARD_LED)
    pprint(l)
    # Set the output to 0 = Low
    board.digital_write(BOARD_LED, 0)
    board.set_digital_latch(BOARD_LED, board.DIGITAL_LATCH_LOW)
    board.pin_state_query(BOARD_LED)
    # Wait a half second between toggles.
    time.sleep(.5)
    l = board.get_digital_latch_data(BOARD_LED)
    pprint(l)

# Close PyMata when we are done
board.close()
コード例 #3
0
firmata.set_pin_mode(BUTTON_SWITCH, firmata.INPUT, firmata.DIGITAL)

# Arm pin A2 for latching a value >= 678
firmata.set_analog_latch(POTENTIOMETER, firmata.ANALOG_LATCH_GTE, 678)

# Arm pin 12 for latching when the pin goes high
firmata.set_digital_latch(BUTTON_SWITCH, firmata.DIGITAL_LATCH_HIGH)

print "start waiting"
# wait for 5 seconds to allow user interaction with switch and pot
# during this time press and release the switch and turn the pot to maximum

time.sleep(5)

print 'end waiting'
# get and print the digital latched data
print firmata.get_digital_latch_data(BUTTON_SWITCH)

# get and print the analog data latched data
a_latch = firmata.get_analog_latch_data(POTENTIOMETER)
print a_latch
# print gmtime for the time stamp
print time.gmtime(a_latch[firmata.LATCHED_TIME_STAMP])

# wait 2 more seconds and see that the latch entry data is now cleared

time.sleep(2)
print firmata.get_digital_latch_data(BUTTON_SWITCH)
print firmata.get_analog_latch_data(POTENTIOMETER)

firmata.close()