Hey, I am trying to fade an RGB LED between to colours.
I am using this code I've adapted from someone in the forums:
void FadeLED(int steps, int fadedelay, byte* fromColor, byte* tooColor)
{
byte* endColor;
for (int fadeindex = 0; fadeindex < steps+1; fadeindex++)
{
endColor[0] = ((fromColor[0] * (steps - fadeindex) + (tooColor[0] * fadeindex))/steps);
endColor[1] = ((fromColor[1] * (steps - fadeindex) + (tooColor[1] * fadeindex))/steps);
endColor[2] = ((fromColor[2] * (steps - fadeindex) + (tooColor[2] * fadeindex))/steps);
setColor(endColor);
delay(fadedelay);
Serial.println(" ");
Serial.print("fromColor: ");
Serial.print(int(fromColor[0]));
Serial.print("-");
Serial.print(int(fromColor[1]));
Serial.print("-");
Serial.println(int(fromColor[2]));
Serial.print("endColor: ");
Serial.print(int(endColor[0]));
Serial.print("-");
Serial.print(int(endColor[1]));
Serial.print("-");
Serial.println(int(endColor[2]));
Serial.print("tooColor: ");
Serial.print(int(tooColor[0]));
Serial.print("-");
Serial.print(int(tooColor[1]));
Serial.print("-");
Serial.println(int(tooColor[2]));
Serial.println(" ");
Serial.println(fadeindex);
}
}
But it's not producing the results I was expecting.
On the serial monitor I see:
fromColor: 96-1-0
endColor: 198-0-0
tooColor: 14-96-0
0
fromColor: 96-1-0
endColor: 198-0-0
tooColor: 14-96-0
1
fromColor: 96-1-0
endColor: 198-0-0
tooColor: 14-96-0
2
fromColor: 96-1-0
endColor: 198-0-0
tooColor: 14-96-0
3
and so on...
I was expecting for the endColour variable to be changing between fromColor and tooColor, but it just stays the same.
Am I missing something obvious?
I have tried punching the numbers into a calculator and it produces the correct results, so im guessing its a programming mistake.
Anyone shed any light on this?
Cheers,
Phil