Serial Interrupters for Animation Switching? - Uno, FastLED, && Max for Live

To break out of a function, you could abort early with "return":

if(Serial.available()) return;"

https://docs.arduino.cc/language-reference/en/structure/control-structure/return/

Although it is possible to escape with break and return, it is better to write the animations to not kneecap the rest of the program by trapping the processor within themselves. The advice to break loops in:

One commonly suggested solution to the responsiveness problem is to check your switches inside your loops and quit the loop if a switch is pressed. The switch check can be neatly combined with the delay. And the loop can be re-written to exit early.

This does make your program more responsive, but there are a couple of fundamental problems with this approach:

  • You are still using delay(), so you still can't do two (or more) patterns at once.
  • And what if you don’t really want to quit? We want a way to remain responsive - without necessarily disturbing the execution of the pattern.