Picaxe 18X I2C communications with PCA9622 I2C PWM LED driver, ROYGBIV color fade

sniper887

Member
18x PCA9622 copy.jpgTook me a while to crack this, getting the I2C commands to work on the PCA9622. This circuit controls a single RGB LED and fades through the colors of the spectrum. Now to find something to light up with it. With the WRITEI2C
commands the PCA9622 wouldn't work unless I took out the register address part of the command. Each WRITEI2C command for this particular device starts with the first byte which is the address pointer (with autoincrement options, used on the "outcolor" subroutine), then the second byte is the data for that particular register. If autoincrement is enabled with the address pointer byte then subsequent bytes go into sequential register addresses starting with the one selected in the pointer byte. That way it's one command to set pwm levels for all 3 colors of the RGB LED.

Code:
symbol blue = b0
symbol green = b1
symbol red = b2
i2cslave %00111110, i2cslow, i2cbyte



start:

writei2c ($00,%10000001)'mode register 1
pause 5
writei2c ($01,%00000101)'mode register 2
pause 5
writei2c ($14,%10101010)'LED0-LED3 output state control, set to respond to LEDx duty cycle registers
pause 5

b0 = 0
b1 = 0
b2 = 0


lightup:

redcolor:


for b3 = 0 to 252 step 2

blue = blue - 2 min 2

gosub outcolor
next b3

b3 = 0
'yellow
for b3 = 0 to 252 step 2

green = green + 2 max 252
gosub outcolor
next b3

'grn

for b3 = 0 to 252 step 2
red = red - 2 min 2

gosub outcolor
next b3

'bluelight
for b3 = 1 to 252 step 2
green = green - 2 min 2

blue = blue + 2 max 252

gosub outcolor
next b3

red = 1
for b5 = 1 to 252 step 2
red = red + 2 max 252
gosub outcolor

next b5


goto lightup

outcolor:

writei2c ($a2, blue, green, red)

gosub speed
pause b8
return
speed:
readadc 2, b8
b8 = b8 / 10
return

Youtube video of it in action:

http://www.youtube.com/watch?v=lZVmHGl2wLI
 
Last edited:

MPep

Senior Member
Hey Sniper,

Love the YouTube video. Appeared very smooth. Congrats on a job well done.

MPep
 

sniper887

Member
Thanks for viewing the vid and for the comment. Now I'm trying to figure out something to light up with that that'll look cool in my living room.
 
Top