io.set_port_pullups(1, 0x00)
io.set_port_direction(0, 0xFF)
io.set_port_direction(1, 0xFF)

# Set the interrupt polarity to be active high and mirroring disabled, so
# pins 1 to 8 trigger INT A and pins 9 to 16 trigger INT B
io.set_interrupt_polarity(1)
io.mirror_interrupts(0)

# Set the interrupts default value to trigger when 5V is applied to pins 1
# and 16
io.set_interrupt_defaults(0, 0x01)
io.set_interrupt_defaults(0, 0x80)

# Set the interrupt type to be 1 for ports A and B so an interrupt is
# fired when the pin matches the default value
io.set_interrupt_type(0, 1)
io.set_interrupt_type(1, 1)

# Enable interrupts for pins 1 and 16
io.set_interrupt_on_pin(1, 1)
io.set_interrupt_on_pin(16, 1)

while True:

    # read the port value from the last capture for ports 0 and 1.  This will
    # reset the interrupts
    print(io.read_interrupt_capture(0))
    print(io.read_interrupt_capture(1))
    time.sleep(2)
io.set_port_direction(0, 0xFF)
io.set_port_direction(1, 0xFF)

# Set the interrupt polarity to be active high and mirroring disabled, so
# pins 1 to 8 trigger INT A and pins 9 to 16 trigger INT B
io.set_interrupt_polarity(1)
io.mirror_interrupts(0)

# Set the interrupts default value to trigger when 5V is applied to pins 1
# and 16
io.set_interrupt_defaults(0, 0x01)
io.set_interrupt_defaults(0, 0x80)

# Set the interrupt type to be 1 for ports A and B so an interrupt is
# fired when the pin matches the default value
io.set_interrupt_type(0, 1)
io.set_interrupt_type(1, 1)

# Enable interrupts for pins 1 and 16
io.set_interrupt_on_pin(1, 1)
io.set_interrupt_on_pin(16, 1)


while True:

    # read the port value from the last capture for ports 0 and 1.  This will
    # reset the interrupts
    print (io.read_interrupt_capture(0))
    print (io.read_interrupt_capture(1))
    time.sleep(2)
Beispiel #3
0
io.set_port_pullups(1, 0x00)
io.set_port_direction(0, 0xFF)
io.set_port_direction(1, 0xFF)

# Set the interrupt polarity to be active high and mirroring disabled, so
# pins 1 to 8 trigger INT A and pins 9 to 16 trigger INT B
io.set_interrupt_polarity(1)
io.mirror_interrupts(0)

# Set the interrupts default value to trigger when 5V is applied to pins 1
# and 16
io.set_interrupt_defaults(0, 0x01)
io.set_interrupt_defaults(0, 0x80)

# Set the interrupt type to be 1 for ports A and B so an interrupt is
# fired when the pin matches the default value
io.set_interrupt_type(0, 1)
io.set_interrupt_type(1, 1)

# Enable interrupts for pins 1 and 16
io.set_interrupt_on_pin(1, 1)
io.set_interrupt_on_pin(16, 1)

while True:

    # read the port value from the last capture for ports 0 and 1.  This will
    # reset the interrupts
    print io.read_interrupt_capture(0)
    print io.read_interrupt_capture(1)
    time.sleep(2)
io.set_port_direction(0, 0xFF)
io.set_port_direction(1, 0xFF)

# Set the interrupt polarity to be active high and mirroring disabled, so
# pins 1 to 8 trigger INT A and pins 9 to 16 trigger INT B
io.set_interrupt_polarity(1)
io.mirror_interrupts(0)

# Set the interrupts default value to trigger when 5V is applied to pins 1
# and 16
io.set_interrupt_defaults(0, 0x01)
io.set_interrupt_defaults(0, 0x80)

# Set the interrupt type to be 1 for ports A and B so an interrupt is
# fired when the pin matches the default value
io.set_interrupt_type(0, 1)
io.set_interrupt_type(1, 1)

# Enable interrupts for pins 1 and 16
io.set_interrupt_on_pin(1, 1)
io.set_interrupt_on_pin(16, 1)


while True:

    # read the port value from the last capture for ports 0 and 1.  This will
    # reset the interrupts
    print io.read_interrupt_capture(0)
    print io.read_interrupt_capture(1)
    time.sleep(2)