import smbus
import time

I2C_ADDR_1 = 0x38
I2C_ADDR_2 = 0x39
I2C_ADDR_3 = 0x3A

LED_ON = 0x00
LED_OFF = 0xFF

LED_1_OFF = 0xFF
LED_1_G1  = 0xFE
LED_1_G2  = 0xFC
LED_1_G3  = 0xF8
LED_1_Y1  = 0xF0
LED_1_Y2  = 0xE0
LED_1_Y3  = 0xC0
LED_1_R1  = 0x80
LED_1_R2  = 0x00
LED_1_ON  = 0x00

LED_2_OFF = 0xFF
LED_2_G1  = 0xFE
LED_2_G2  = 0xFC
LED_2_G3  = 0xF8
LED_2_Y1  = 0xF0
LED_2_Y2  = 0xE0
LED_2_Y3  = 0xC0
LED_2_R1  = 0x80
LED_2_R2  = 0x00
LED_2_ON  = 0x00

LED_3_OFF = 0xFF
LED_3_R1B = 0xFE
LED_3_R2B = 0xFD
LED_3_G1B = 0xFB
LED_3_Y1B = 0xF7
LED_3_R1T = 0xEF
LED_3_R2T = 0xDF
LED_3_G1T = 0xBF
LED_3_Y1T = 0x7F

LED_1_DATA = (0x7F, 0xBF, 0xDF, 0xEF, 0xF7, 0xFB, 0xFD, 0xFE) 
 
bus = smbus.SMBus(1)

#while True:
#	for i in range(0,8):
#		#message = "Count=" + str(i) + " Data=" + str(LED_1_DATA[i])
#		#print(message)
#		bus.write_byte( I2C_ADDR_1, LED_1_DATA[i])
#		time.sleep(1)	

while True:
	LED_1 = LED_1_G1
	LED_2 = LED_2_G1
	LED_3 = LED_3_G1T & LED_3_G1B

	bus.write_byte( I2C_ADDR_1, LED_1)
	bus.write_byte( I2C_ADDR_2, LED_2)
	bus.write_byte( I2C_ADDR_3, LED_3)

	time.sleep(1)

while True:
	LED_3 = 0xFF
	for i in range(0,9):
		bus.write_byte( I2C_ADDR_3, LED_3)
		time.sleep(1)	
		LED_3 = ((LED_3 << 1) & 0xFE)

while True:
	LED_2 = 0xFF
	for i in range(0,9):
		bus.write_byte( I2C_ADDR_2, LED_2)
		time.sleep(1)	
		LED_2 = ((LED_2 << 1) & 0xFE)

while True:
	LED_1 = 0xFF
	for i in range(0,9):
		bus.write_byte( I2C_ADDR_1, LED_1)
		time.sleep(1)	
		LED_1 = ((LED_1 << 1) & 0xFE)


while True:
	for i in range(0,3):
		bus.write_byte( I2C_ADDR_1, LED_ON)
		time.sleep(1)	
		bus.write_byte( I2C_ADDR_1, LED_OFF)
		time.sleep(1)
	for i in range(0,3):
		bus.write_byte( I2C_ADDR_2, LED_ON)
		time.sleep(1)	
		bus.write_byte( I2C_ADDR_2, LED_OFF)
		time.sleep(1)
	for i in range(0,3):
		bus.write_byte( I2C_ADDR_3, LED_ON)
		time.sleep(1)	
		bus.write_byte( I2C_ADDR_3, LED_OFF)
		time.sleep(1)
