Another new user that like - almost every week - has difficulties to understand because the BWD-example does NOT emphasize the fundamental difference between delay() and nonblocking timing BASED on millis()
Leaving out this explanation leads to the totally wrong assumption that non-blocking timing would wait similar to delay()
Non-blocking timing checks 10000 of times each second:
"has enough time passed by"?
and only in case of really enough time has passed by take action.
badly chosen variable names
better names:
startOfPeriod
timePassedSincePeriodStarted
actualTime
void loop() {
// This is line #1. It stores the actual time in milliseconds
actualTime = millis();
// Now we calculate the interval between "newTime" and "oldTime"
// This is the time in milliseconds expired since the last time we have stored oldTime
timePassedSincePeriodStarted = (actualTime - startOfPeriod);
// As long as this difference is less than or equal to 1000 msecs
// everything inside the if-clause is skipped!
if (timePassedSincePeriodStarted > 1000 && ledOn == 0) {
digitalWrite(led, HIGH);
ledOn = 1;
startOfPeriod = actualTime ; // update variable startOfPeriod because a NEW periods starts right now
}
// This is the line after this if-clause
// and the end of loop()
// so the controller will proceed with line #1 again
}