you are another victim of the very poor explanations that this famous notorious blink without understand-example code.
There is a fundamental difference between coding timing with delay() which is blocking
and coding non-blocking timing
This difference is:
using delay() means linear-code-execution
non-blocking timing means:
global circular-code-execution
global circular in the sence of the whole void-loop shall run over and over again
looping = run down jump back to the top
run down jump back to the top
run down jump back to the top
run down jump back to the top
and doing this
- fast
- executing each line again and again and again
- repeatedly check how much time has passed by
and only in case a certain amount of time has passed by execute timed actions from time to time
In your code you inserted a while-loop that is blocking again
while (millis() - start <60000)
which means execute only the code inside the while-loop until the condition
millis() - start < 60000 becomes false
this means the other code gets not executed.
to make both parts of the code execute all the time
you code
if (a certain amount of time has passed by) {
execute Action
the if-condition itself is executed with each iteration of loop()
But executing the action is only done in case the if condition becomes true
which happens only after a certain amount of time
The looping is done global by void loop() itself
executing the action that shall only happen from time to time
is IF-conditionally to a certain amount of time.
The details of this time-measuring is to store a reference-point in time
and then do a 100000 times repeated checking with an if-condition
since reference-point has more time than 60000 milliseconds have passed by?
This blink without understand example of the arduino-IDE is unescessary hard to understand because it does
- not explain this fundamental difference between linear-code-execution and globally circular-code-execution
- scatter variables to different places in the code
- uses badly chosen variable names
I claim that I have written a much easier to understand version of non-blocking timing with a tutorial that explains it
I'm very interested in improving this tutorial.
And the best way to improve it is to read questions of newcomers and to answer these questions
best regards Stefan