Delay timer in function without delaying main loop!

This is a minor thing, but a good habit to get into. When you compare against mills, always do it like:

if (millis() - lastTime >= TIME_INVERVAL) {
     lastTime = millis();

The reason is that millis() rolls over, or resets to 0, every 49 days. If your code runs for 49 days, the test written the other way will fail, but the test written this way continues to work properly.

The reason why has to do with how unsigned numbers are represented in C, and a topic of an entire post:

3 Likes