# Set all pins on bus 2 to be inputs with internal pull-ups disabled. bus2.setPortPullups(0, 0x00) bus2.setPortPullups(1, 0x00) bus2.setPortDirection(0, 0xFF) bus2.setPortDirection(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 bus2.setInterruptPolarity(1) bus2.mirrorInterrupts(0) # Set the interrupts default value to trigger when 5V is applied to pins 1 and 16 bus2.setInterruptDefaults(0, 0x01) bus2.setInterruptDefaults(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 bus2.setInterruptType(0, 1) bus2.setInterruptType(1, 1) # Enable interrupts for pins 1 and 16 bus2.setInterruptOnPin(1, 1) bus2.setInterruptOnPin(16, 1) while True: # read the port value from the last capture for ports 0 and 1. This will reset the interrupts print bus2.readInterruptCature(0) print bus2.readInterruptCature(1) time.sleep(2)