I want to describe in my own words what I assume what your code should do:
There is a ring with 12 LEDs
the 12 LEDs shall do one "run" which means each of the 12 LEDs lights up goes off next LED lights up
This shall be repeated for six different colors
After each "run" you would like to pause for eventime with eventime = 1000 milliseconds = 1 second
Then some different patterns follow.
If you analyse my description this description has no programming-terms
This is my pure intention: first a description with zero programming-terms.
Anybody us very familiar with everyday's language. About programming-terms there might be misconceptions and misconceptions are bad base to communicate on.
I'm not sure if I understood what you want to do right. Please confirm or correct my description what functionality you want to achieve with your code. Avoid programming-terms in this description to make sure it is easy to understand and to keep potential misconceptions out.
If all you want to do is a fixed sequence of LED pattern and you want some pausing between LEDs light up and that's all using delay is sufficient. If all your Ardiuno shall do is pausing delay() can be used.
As soon as you want to do another thing in parallel to this LED-switching-sequence the programming has to change to non-blocking timing based on function millis().
For example you want your code to be very responsive to button-presses with minimal latency = fastest reaction as long as a delay() is executed the code could not respond to the button-press
as an everyday example with easy to follow numbers
delay() is blocking. As long as the delay is "delaying" nothing else of the code can be executed.
Now there is a technique of non-blocking timing.
The basic principle of non-blocking timing is fundamental different from using delay()
You have to understand the difference first and then look into the code.
otherwise you might try to "see" a "delay-analog-thing" in the millis()-code which it really isn't
Trying to see a "delay-analog-thing" in millis() makes it hard to understand millis()
Having understood the basic principle of non-blocking timing based on millis() makes it easy to understand.
imagine baking a frosted pizza
the cover says for preparation heat up oven to 200°C
then put pizza in.
Baking time 10 minutes
You are estimating heating up needs 3 minutes
You take a look onto your watch it is 13:02 (snapshot of time)
You start reading the newspaper and from time to time looking onto your watch
watch shows 13:02. 13:02 - 13:02 = 0 minutes passed by not yet time
watch shows 13:03. 13:03 - 13:02 = 1 minute passed by not yet time
watch shows 13:04. 13:04 - 13:02 = 2 minutes passed by not yet time
watch shows 13:05 when did I start 13:02? OK 13:05 - 13:02 = 3 minutes time to put pizza into the oven
New basetime 13:05 (the snapshot of time)
watch 13:06 not yet time
watch 13:07 not yet time
watch 13:08 not yet time (13:08 - 13:05 = 3 minutes is less than 10 minutes
watch 13:09 not yet time
watch 13:10 not yet time
watch 13:11 not yet time
watch 13:12 not yet time
watch 13:13 not yet time
watch 13:14 not yet time (13:14 - 13:05 = 9 minutes is less than 10 minutes
watch 13:15 when did I start 13:05 OK 13:15 - 13:05 = 10 minutes time to eat pizza (yum yum)
You did a repeated comparing how much time has passed by
This is what non-blocking timing does
In the code looking at "How much time has passed by" is done
currentTime - startTime >= bakingTime
bakingTime is 10 minutes
13:06 - 13:05 = 1 minute >= bakingTime is false
13:07 - 13:05 = 2 minutes >= bakingTime is false
...
13:14 - 13:05 = 9 minutes >= bakingTime is false
13:15 - 13:05 = 10 minutes >= bakingTime is TRUE time for timed action!!
So your loop() is doing
void loop()
// doing all kinds of stuff like reading the newspaper
if (currentTime - previousTime >= period) {
previousTime = currentTime; // first thing to do is updating the snapshot of time
// time for timed action
}
it has to be coded exactly this way because in this way it manages the rollover from Max back to zero of the function millis() automatically
Edit to make everything without for-loops the programming-technique of state-machines can be used
I have posted a demo-code that shall show how this works
state-machine demo
best regards Stefan