I’m using a bunch of WS2801s to control RGB LEDs. The code provided takes an RGB value and sticks it in an array before pushing it all down the wire to the various ICs and LED in the chain.
So, assume a strip of 3 IC/LEDs, the array starts off
#define STRIP_LENGTH 3; long strip_colors[STRIP_LENGTH]
From there, I take HEX values for r, g, and b and construct the color before putting it in the array:
r = 0xFF; g = 0x33; b = 0x99; // construct full color value long color = r; color <<= 8; color |= g; color <<= 8; color |= b; // push color into array strip_colors[x] = color;
(where ‘x’ is the LED I want that color)
Lather, rinse, repeat for the remaining LEDs.
After that, everything gets pushed to the string. Now comes my question: how can I fade what’s in the array back to 0x0 (or technically 0x000000, or 0)?
At the point where I need to shut off the string, I can simply stick 0x0 into all the array slots and push the values out. Done, string is off. However, I’m wondering if there’s a way to fade down to 0x0 based on what’s in the array, without knowing the individual values for r, g, and b. Or do I have to calculate what those individual values are before I can do anything?
Any other time I need to fade and I already know what the individual values are, I simply subtract 0x29 (or whatever number) from them till they drop below 0x0 (at which time I force them to 0x0). But since the values in the array are now together, I’m at a loss as to what I can do …
I realize the stuff in the array can be interpreted as either a hex value or a large int … do I translate what i want subtracted into a large int as well and do it that way? Seems too easy … and more often than not, I’m wrong.