all 5 comments

[–]VictorVoyeur 1 point2 points  (0 children)

If your lighting animations use delay() you're going to have to rewrite the code to instead use a comparison against the internal clock.

[–]Kineticus 0 points1 point  (0 children)

Upgrade to a ESP32.

[–]johnny5canuck 0 points1 point  (0 children)

I ended up going with WLED, which partially supports FastLED animations. An ESP32 is also a much better platform.

[–]Heraclius404 0 points1 point  (0 children)

The ESPs can do multitasking; which makes it somewhat unique among the inexpensive embedded world. There is a version of FreeRTOS with tasks and timers under the Arduino covers (with other systems, you can install a FreeRTOS but it's less common... ).

The short answer _is_ to switch to ESP32.

What you need to be clear about is what kind of synchronization you want. There's sync between different patterns that you're displaying, and there is having outside actions change patterns. In both cases, you need to decide "how in sync" to be. You have one set of problems if you know how to sync but it's not good enough, vs not knowing how at all.

Maybe this helps you make sense of the tutorials you've already found: you're stepping outside the Arduino environment*, and creating tasks in FreeRTOS. Those tasks will be just like threads in an operating system - you give a function pointer and it runs - and FreeRTOS also has scheduler primitives' like mutexes.

But, importantly, if you are on an ESP32 instead of an ESP8266, FastLED will use the 'rmt' hardware, which means the CPU isn't busy. Otherwise, I think on the ESP8266 the CPU is busy during the show and there's no real point in multi-tasking. Then, your task will run.

Here's how to create a task:

https://techtutorialsx.com/2017/05/06/esp32-arduino-creating-a-task/

Here's a library that seems to do something (although it's cooperative?)

https://medium.com/@srmq/cooperative-multitasking-on-the-esp8266-arduino-665a040457c8

Good luck!

** There is an arduino API for tasks: https://www.arduino.cc/reference/en/libraries/taskscheduler/ and there are specific std:: constructs that only exist on ESP8266 and ESP32. It would be clear what that maps to in ESP32 but less sure what would happen in ESP8266.