What am I missing?
Comments on ORIGINAL code , may be irrelevant by now.
- you are not checking current time in for() loop
if (currentMillis - previousMillis >= interval) {
should be
if (millis() - previousMillis >= interval) {
2.AS written with "previousMillis" , the if() code is dependent on HOW long has program been running - millis() is a counter initialized to zero at program start. - the if() will always initially evaluate to true ( millis() - 0 > interval) initially
- next line has same issue as #1, and initially "preiviousMillis" will be set pretty close to "currentMilis"
previousMillis = currentMillis;
and it is not clear what is "previousMillis" function anyway.
Basically - you do not need "currentMillis" variable - use millis() function it its place.
Safer and "self documenting" that way.
It is really unnecessary to name "previousMillis" if you really want to know "lastTime" the function / event was used.
.