#!/usr/bin/python ######################################################################## # # Matrix3: test of Pi Matrix board # # This application will test out your Pi LED 8x8 Matrix board # by selectively turning on and off each row, column, and pixel. # # Use the concepts from these simple test routines # to make more interesting displays. # # Author: Bruce E. Hall # Date : 03 Feb 2013 # ######################################################################## import smbus #gives us a connection to the I2C bus import time #for timing delays #Definitions for the MCP23017 chip ADDR = 0x20 #The I2C address of our chip DIRA = 0x00 #PortA I/O direction, by pin. 0=output, 1=input DIRB = 0x01 #PortB I/O direction, by pin. 0=output, 1=input PORTA = 0x12 #Register address for PortA PORTB = 0x13 #Register address for PortB OUTPUT = 0 INPUT = 1 # # Lower Level LED Display routines # Write data directly to the Pi Matrix board # def Init23017 (): #Set up the 23017 for 16 output pins bus.write_byte_data(ADDR,DIRA,0x00); #all zeros = all outputs on PortA bus.write_byte_data(ADDR,DIRB,0x00); #all zeros = all outputs on PortB def TurnOffLEDS (): bus.write_byte_data(ADDR,PORTA,0x00) #set all columns low bus.write_byte_data(ADDR,PORTB,0x00) #set all rows low def TurnOnLEDS (): bus.write_byte_data(ADDR,PORTA,0xFF) #set all columns low bus.write_byte_data(ADDR,PORTB,0x00) #set all rows low def SetLED (row,col): #turn on an individual LED at (row,col). All other LEDS off. bus.write_byte_data(ADDR,PORTA,0x80>>col) bus.write_byte_data(ADDR,PORTB,~(1<>col) def SetRow (row): #turn on all LEDs in the specified row. expects input of 0-7 bus.write_byte_data(ADDR,PORTA,0xFF) bus.write_byte_data(ADDR,PORTB,~(1<