adafruit_support_bill wrote:Rstart is the red value you want to start with (255)
Rend is the red value you want to end with (0)
Same for the green (0 and 255) and blue (0 and 0)
Let's say I have the following function where command is equal to an RGB color (e. g. 255, 0, 0):
- Code: Select all | TOGGLE FULL SIZE
int setColour(String command)
// Clear strip.
int commaIndex = command.indexOf(',');
int secondCommaIndex = command.indexOf(',', commaIndex+1);
int lastCommaIndex = command.lastIndexOf(',');
int red = command.substring(0, commaIndex).toInt();
int grn = command.substring(commaIndex+1, secondCommaIndex).toInt();
int blu = command.substring(lastCommaIndex+1).toInt();
int Rstart = ?, Gstart = ?, Bstart = ?;
int Rend = ?, Gend = ?, Bend = ?;
int Rnew = ?, Gnew = ?, Bnew = ?;
int n = 200;
for (int i = 0; i < n; i++) // larger values of 'n' will give a smoother/slower transition.
Rnew = Rstart + (Rend - Rstart) * i / n;
Gnew = Gstart + (Gend - Gstart) * i / n;
Bnew = Bstart + (Bend - Bstart) * i / n;
// Set pixel color here.
strip.setPixelColor(0, strip.Color(Rnew, Gnew, Bnew));
How would I go about ensuring that any RGB color fades from old to new. Am I on the right track with the above code? Would I have to store the old value somewhere so the algorithm knows what to fade to? I'm trying to better understand how that loop works from color to color.
Keep in mind I have a total of 72 LED's that I need to light up at any given time as well.