Overlay animations: I’m still mostly in the learning phase. I currently have a string that’s ordinarily running a rainbow animation (stolen from DemoReel100). I’d like to “overlay” an animation on top of the rainbow when our gate opens or closes (I receive these events via MQTT). Currently, I’m doing the animation in loop(), which blocks the normal update sequence for the rainbow:
if (gateAnimation > 0) {
Serial.print(“Running gate open animation\n”);
for (int i = NUM_LEDS/2; i >= 0; i–) {
CRGB left = leds[vINDEX(i)];
CRGB right = leds[vINDEX(NUM_LEDS-i)];
leds[vINDEX(i)] = CRGB::White;
leds[vINDEX(NUM_LEDS-i)] = CRGB::White;
FastLED.show();
delay(20);
leds[vINDEX(i)] = left;
leds[vINDEX(NUM_LEDS-i)] = right;
}
gateAnimation = 0;
}
(Currently, vINDEX(i) is defined as (i) – I borrowed this code from another app where one string is reversed, and vINDEX remaps that)
This works well (it shows a pair of white dots moving outward from the center to the ends), but I’d like to leave the ends white until the gate closes. I could do this with a special case between fill_rainbow() and FastLED.show() in each iteration, but I’d rather have a more general solution, as my end goal would be to make the gate animation more sophisticated.
I’m thinking of going to three CRGB arrays: “base”, “overlay” and “output”.
Normal animations would run in the base array, overlay would do their thing in that array, and prior to show(), I would set the output array to base if the corresponding overlay is black, otherwise, to the overlay. I don’t envision any giant displays, so the triple space isn’t an immediate problem.
This seems workable, and not too ugly, but I wanted to run it by the more experienced folks here in case I’m missing something much better.