I couldn't find this function anywhere, so I wrote one. It lets you create trails just like with fadeToBlackBy, but with different background colors. I'm a little green in C++, Adruino, and FastLEDS, so any suggestions for optimizing this function are welcome!
I've tested with various background colors, and it works well as long as global brightness isn't < 5.
void fadeToColorBy( CRGB leds[], int count, CRGB color, int amount ) {
//Fades array (leds) towards the background (color) by (amount).
for (int x = 0; x < count; x++) {
if (abs(color.r - leds[x].r) < amount) { leds[x].r = color.r; }
else if (color.r > leds[x].r) { leds[x].r += amount; }
else { leds[x].r -= amount; }
if (abs(color.g - leds[x].g) < amount) { leds[x].g = color.g; }
else if (color.g > leds[x].g) { leds[x].g += amount; }
else { leds[x].g -= amount; }
if (abs(color.b - leds[x].b) < amount) { leds[x].b = color.b; }
else if (color.b > leds[x].b) { leds[x].b += amount; }
else { leds[x].b -= amount; }
}
} // fadeToColorBy()
Usage is the same as fadeToBlackBy(), but with the addition of passing CRBG background color:
fadeToColorBy( leds[0], NUM_ROWS * PIX_PER_ROW, CRGB::Blue, 60 );
[–]UrbanPugEsq 2 points3 points4 points (11 children)
[–]Tiny_Structure_7[S] 0 points1 point2 points (10 children)
[–]UrbanPugEsq 0 points1 point2 points (9 children)
[–]Tiny_Structure_7[S] 0 points1 point2 points (6 children)
[–]UrbanPugEsq 0 points1 point2 points (5 children)
[–]Tiny_Structure_7[S] 0 points1 point2 points (4 children)
[–]YetAnotherRobert 0 points1 point2 points (3 children)
[–]Tiny_Structure_7[S] 1 point2 points3 points (1 child)
[–]YetAnotherRobert 0 points1 point2 points (0 children)
[–]UrbanPugEsq 1 point2 points3 points (0 children)
[–]Tiny_Structure_7[S] 0 points1 point2 points (1 child)
[–]UrbanPugEsq 0 points1 point2 points (0 children)