Example ARDX v1.3 CIRC-12 code at http://ardx.org/RGBANA bugfix

For makers who have purchased an Adafruit Starter Pack, get help with the tutorials here!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
vjqak
 
Posts: 3
Joined: Sat Jan 29, 2011 6:22 pm

Example ARDX v1.3 CIRC-12 code at http://ardx.org/RGBANA bugfix

Post by vjqak »

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

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm

Re: Example ARDX v1.3 CIRC-12 code at http://ardx.org/RGBANA bugfix

Post by adafruit »

thats a good point, thanks for letting us know!

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Starter Pack”