#!/usr/bin/python from Adafruit_I2C import Adafruit_I2C from Adafruit_MCP230xx import Adafruit_MCP230XX import smbus import time def lightRGBLed(rState,gState,bState,rPin,gPin,bPin): mcp.output(rPin, rState) mcp.output(gPin, gState) mcp.output(bPin, bState) def lightRGBLed2(color,rPin,gPin,bPin): if color == 'red': lightRGBLed(0,1,1,rPin,gPin,bPin) elif color == 'green': lightRGBLed(1,0,1,rPin,gPin,bPin) elif color == 'blue': lightRGBLed(1,1,0,rPin,gPin,bPin) elif color == 'yellow': lightRGBLed(0,0,1,rPin,gPin,bPin) elif color == 'magenta': lightRGBLed(0,1,0,rPin,gPin,bPin) elif color == 'cyan': lightRGBLed(1,0,0,rPin,gPin,bPin) elif color == 'white': lightRGBLed(0,0,0,rPin,gPin,bPin) if __name__ == '__main__': mcp = Adafruit_MCP230XX(busnum = 1, address = 0x20, num_gpios = 16) r1=7 g1=6 b1=5 mcp.config(b1, mcp.OUTPUT) mcp.config(g1, mcp.OUTPUT) mcp.config(r1, mcp.OUTPUT) while (True): print "off" lightRGBLed(1,1,1,r1,g1,b1) time.sleep(1) print "red" lightRGBLed(0,1,1,r1,g1,b1) time.sleep(1) print "green" lightRGBLed(1,0,1,r1,g1,b1) time.sleep(1) print "blue" lightRGBLed(1,1,0,r1,g1,b1) time.sleep(1) print "green+blue" lightRGBLed(1,0,0,r1,g1,b1) time.sleep(1) print "red+blue" lightRGBLed(0,1,0,r1,g1,b1) time.sleep(1) print "red+green" lightRGBLed(0,0,1,r1,g1,b1) time.sleep(1) print "red+green+blue" lightRGBLed(0,0,0,r1,g1,b1) time.sleep(1)