Multiplex pwm_32 led question.
I am working on a small RGB LED project and have run into some issues while trying to multiplex them. Nonsensical flashing etc. I am stuck with a hardware device where 4 x common cathode RGB led's all share the R, G, and B anodes.
That is I have 3 PWM pins to change the RGB values for all four lights at once and 4 pins which each illuminate an led when it is pulled low. This doesn't seem, like the best way to set this up but... here it is.
To dim the led's I am using PWM on their cathodes. I figure this will be easier than "dimming" each color on the driven side of the LED's while accounting for the brightness curves of each R G and B etc.
The controls work for one led at a time but I can't get more than one color to "display" at once.
Each pin is limited to ~15ma and the problems don't hint at being current related..
I have a loop that is supposed to multiplex the LED's retrieving the newest values from data
The main idea is:
I hope to have objects in another cog update these data values on the fly...
I don't think that my code is sound, any one have any ideas?
That is I have 3 PWM pins to change the RGB values for all four lights at once and 4 pins which each illuminate an led when it is pulled low. This doesn't seem, like the best way to set this up but... here it is.
To dim the led's I am using PWM on their cathodes. I figure this will be easier than "dimming" each color on the driven side of the LED's while accounting for the brightness curves of each R G and B etc.
The controls work for one led at a time but I can't get more than one color to "display" at once.
Each pin is limited to ~15ma and the problems don't hint at being current related..
I have a loop that is supposed to multiplex the LED's retrieving the newest values from data
The main idea is:
PRI LEDmux | id, clr, i repeat 'forever repeat id from 0 to 3 ' index through LED #0 to #3 repeat clr from 0 to 3 'clear all lights PWM.DutyMode(_LEDBASEPIN+clr,2) repeat i from 0 to 2 PWM.PWM(_COLOURBASEPIN + i,100,LEDColourREG[(id*3)+ i]) 'PWM out the R,G,B values for the given ID of the light PWM.DutyMode(_LEDBASEPIN+clr,1) PWM.Duty(_LEDBASEPIN+id,LEDvelREG[id],10) 'Turn LED on at duty held in LEDvelREG DAT 'LED 1 LEDColourREG byte 99, 0, 0 byte 0, 99, 0 byte 0, 0, 99 byte 50, 50, 50 'LED brightness LEDvelREG byte 10, 34, 70, 99
I hope to have objects in another cog update these data values on the fly...
I don't think that my code is sound, any one have any ideas?