# We will write to the pins 9 to 16 from bus 1 so set port 1 to be outputs turn off the pins bus1.setPortDirection(1, 0x00) bus1.writePort(1, 0x00) while True: # count to 255 and display the value on pins 9 to 16 in binary format for x in range(0, 255): time.sleep(0.05) bus1.writePort(1, x) # turn off all of the pins on bank 1 bus1.writePort(1, 0x00) # now turn on all of the leds in turn by writing to one pin at a time bus1.writePin(9, 1) time.sleep(0.1) bus1.writePin(10, 1) time.sleep(0.1) bus1.writePin(11, 1) time.sleep(0.1) bus1.writePin(12, 1) time.sleep(0.1) bus1.writePin(13, 1) time.sleep(0.1) bus1.writePin(14, 1) time.sleep(0.1) bus1.writePin(15, 1) time.sleep(0.1) bus1.writePin(16, 1)
# ================================================ # ABElectronics IO Pi 32-Channel Port Expander - Tutorial 1 # Version 1.1 Created 10/05/2014 # # Requires python smbus to be installed with: sudo apt-get install python-smbus # run with: sudo python tutorial1.py # ================================================ # This example uses the writePin and writePort methods to switch pin 1 on and off on the IO Pi. #!/usr/bin/python from ABElectronics_IOPi import IOPI import time bus = IOPI(0x21) bus.setPortDirection(0, 0x00) bus.writePort(0, 0x00) while True: bus.writePin(1, 1) time.sleep(1) bus.writePin(1, 0) time.sleep(1)
# ================================================ # This example uses the writePin and writePort methods to switch pin 1 on and off on the IO Pi. #!/usr/bin/python from ABElectronics_IOPi import IOPI import time bus = IOPI(0x21) bus.setPinDirection(1, 1) # set pin 1 as an input bus.setPinDirection(8, 0) # set pin 8 as an output bus.writePin(8,0) # turn off pin 8 bus.setPinPullup(1, 1) # enable the internal pull-up resistor on pin 1 bus.invertPin(1, 1) # invert pin 1 so a button press will register as 1 while True: if bus.readPin(1) == 1: # check to see if the button is pressed print 'button pressed' # print a message to the screen bus.writePin(8, 1) # turn on the led on pin 8 time.sleep(2) # wait 2 seconds else: bus.writePin(8, 0) # turn off the led on pin 8