Example #1
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
    # re-arm the latch to fire on the next transition to high
    board.set_digital_latch(PUSH_BUTTON, board.DIGITAL_LATCH_HIGH, cb_push_button)



def signal_handler(sig, frame):
    print('You pressed Ctrl+C!!!!')
    if board is not None:
        board.reset()
    sys.exit(0)


signal.signal(signal.SIGINT, signal_handler)

# create a PyMata instance
board = PyMata("/dev/ttyACM0")


# set pin modes
# set the pin to light the green led
board.set_pin_mode(GREEN_LED, board.OUTPUT, board.DIGITAL)

# set the pin to receive button presses
board.set_pin_mode(PUSH_BUTTON, board.INPUT, board.DIGITAL)

# arm the digital latch to detect when the button is pressed
board.set_digital_latch(PUSH_BUTTON, board.DIGITAL_LATCH_HIGH, cb_push_button)

while 1:
    pass
Example #3
0
    # re-arm the latch to fire on the next transition to high
    board.set_digital_latch(PUSH_BUTTON, board.DIGITAL_LATCH_HIGH,
                            cb_push_button)


def signal_handler(sig, frame):
    print('You pressed Ctrl+C!!!!')
    if board is not None:
        board.reset()
    sys.exit(0)


signal.signal(signal.SIGINT, signal_handler)

# create a PyMata instance
board = PyMata("/dev/ttyACM0")

# set pin modes
# set the pin to light the green led
board.set_pin_mode(GREEN_LED, board.OUTPUT, board.DIGITAL)

# set the pin to receive button presses
board.set_pin_mode(PUSH_BUTTON, board.INPUT, board.DIGITAL)

# arm the digital latch to detect when the button is pressed
board.set_digital_latch(PUSH_BUTTON, board.DIGITAL_LATCH_HIGH, cb_push_button)

while 1:
    pass
print firmata.get_firmata_version()

# Print PyMata's version number
print firmata.get_pymata_version()

# Setup pin A2 for input
firmata.set_pin_mode(POTENTIOMETER, firmata.INPUT, firmata.ANALOG)

# Setup pin pin 12 for the switch
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 firmata.get_firmata_version()

# Print PyMata's version number
print firmata.get_pymata_version()

# Setup pin A2 for input
firmata.set_pin_mode(POTENTIOMETER, firmata.INPUT, firmata.ANALOG)

# Setup pin pin 12 for the switch
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