the thing that makes the effect work is: calling the function
when you tested your code - you really did a function-CALL
void loop() {
//fadeAnimationWrapper();
cylon(); // <<<<<<< THIS line of code is the function-CALL which makes the microcontroller EXECUTE the lines of code inside function cylon()
//sparkles();
//changeEffect();
}
void loop() {
//fadeAnimationWrapper();
//cylon();
sparkles(); // <<<<<<< THIS line of code is the function-CALL which makes the microcontroller EXECUTE the lines of code inside function sparkles()
//changeEffect();
}
In the code you have posted there are no function-CALLs for cylon(), sparkles(), etc.
You are a victim of the bad habit of "professional" code-writers to use very similar names for completely different things. (shame on all these "professional" code-writers!!")
As long as you do not know the differences between what do the code-lines
1. defining an enumeration
enum class effectState : uint8_t {
sparkles,
fadeAnimationWrapper,
cylon,
};
and the
2. declaring a function
void cylon() {
static uint8_t hue = 0;
Serial.print("x");
// First slide the led in one direction
for (int i = 0; i < NUM_LEDS; i++) {
.......
fadeall();
// Wait a little bit before we loop around and do it again
delay(10);
}
}
and a
3. function-CALL of a function
void loop() {
...
cylon(); // <<<< this is the function-CALL for function cylon()
...
You experience what you have experienced.
In addition to this:
as long as the animations run in inner-loops
these functions are blocking
For making the code responsive to a button-press all the time there are two ways:
the ugly way:
adding code that reads in the IO-pin in
- each and every for-loop
- each and every while-loop
the elegant way
restructuring / re-designing the code that the single - one and only loop that exists is
void loop()
and all functions work in a quickly jump-in / jump-out-manner
void loop is the most outerside loop
If some lines of code shall be executed only at certain conditions these lines of code
are inside a conditional-statement beeing a
- switch case
or - if-condition
So there are some new things to learn for you.
I remembered that I started a tutorial about non-blocking coding. I haven't finished it yet.
But as a first part it still makes sense to publish it in the introductional tutorial section
best regards Stefan