Change the fadeToColor() function to use longs instead of ints, from:
void fadeToColor(int* led, byte* startColor, byte* endColor, int fadeSpeed){
int changeRed = endColor[0] - startColor[0]; //the difference in the two colors for the red channel
int changeGreen = endColor[1] - startColor[1]; //the difference in the two colors for the green channel
int changeBlue = endColor[2] - startColor[2]; //the difference in the two colors for the blue channel
to:
void fadeToColor(int* led, byte* startColor, byte* endColor, int fadeSpeed){
long changeRed = endColor[0] - startColor[0]; //the difference in the two colors for the red channel
long changeGreen = endColor[1] - startColor[1]; //the difference in the two colors for the green channel
long changeBlue = endColor[2] - startColor[2]; //the difference in the two colors for the blue channel
This fixed rounding errors I was running into here:
int newRed = startColor[0] + ((i * changeRed) / steps);
The (i * changeRed/Green/Blue) was overflowing, since ints can only be between -32768 and 32767, which was causing fades between colors to jump unexpectedly. Just an FYI, you might want to update the source
Example ARDX v1.3 CIRC-12 code at http://ardx.org/RGBANA bugfix
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
-
- Posts: 3
- Joined: Sat Jan 29, 2011 6:22 pm
-
- Posts: 12151
- Joined: Thu Apr 06, 2006 4:21 pm
Re: Example ARDX v1.3 CIRC-12 code at http://ardx.org/RGBANA bugfix
thats a good point, thanks for letting us know!
Please be positive and constructive with your questions and comments.