I have some FastLED code managing LED strips above/under my kitchen cabinets with ESP8266 controll to allow remote change of colors or brightness. Working perfectly.
Now, I was thinking about Christmas Tree or house lights. I would want to have multiple routines that can not only do colors/brightness, but different patterns or routines.
I can see where a specific pattern could take several minutes to complete.
I want to be able to break out of it if a change to a new pattern was selected.
If in my loop() code, I am checking for new pattern (using MQTT or remote control) if I then call a long running pattern how can I come back periodically and check for new input, rather than waiting for the pattern to complete and control to pass back to the main loop().
Can anyone point me to a code example of the best way to do this?
Most people here recommend you avoid long running loops and delays in your code, especially in your patterns/animations. Each pass through loop() should handle new input, update any state, and draw out one frame, all as fast as possible (like a game loop). If you need to slow an animation down, you handle it using a real-time based timer method, such as EVERY_N_MILLIS or elapsedMillis. This allows you to switch to a new pattern at any time. This is a great, fairly simple example: https://github.com/FastLED/FastLED/blob/master/examples/DemoReel100/DemoReel100.ino
I’m using ESP8266-12 and 12e, so I do have WiFi. In fact as I said, I am using MQTT for command and state, linked up to a Home Automation system and that part works fine. I think these examples will get me on the path that I need to be on.