I have some FastLED code managing LED strips above/under my kitchen cabinets with ESP8266

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?

I’d start with the excellent example from @Jason_Coon ​, here’s a link to the post https://plus.google.com/+JasonCoon1/posts/QhFE7hwmxBn

Just to add for clarity:

loop() {
check for new command;
newCommand();
}

newCommand() {
//This runs a light pattern for 5 mins, for example
}

When newCommand is running, I would like to be able to check for another command, rather than have to wait until it finishes.

I have some code derrived from some code from Adafruit for their circuit playground that changes quickly and at any point in a pattern…

Here is a link to it on my github, it is modular and allows for addition and removal easily from the master .ino file…

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

What ESP8266 board are you using? I use a Wemos D1 mini for a lot of my projects and use a phone app called Blynk for controlling them. Like Jason said, as long as you avoid using any long delays in your code the animation change should be instantaneous. Or you could look at https://github.com/jasoncoon/esp8266-fastled-webserver
https://github.com/jasoncoon/esp8266-fastled-webserver

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.

Thanks for the quick replies!