Difference between Software Timer and using mills()

I prefer to use millis() checked from loop whenever possible. The reason is that software timers can get you into all sorts of unexpected problems because they run in a separate thread with a small stack. There are calls you just can’t make from a software timer, and there’s always a possibility of a thread synchronization error, which can be hard to debug.

Just remember to always use the pattern:

if (millis() - lastTime >= timeBetweenCalls)

As long as you always write your code like that, it will behave correctly when the mills() counter rolls over, every 49 days. This post explains why that works.

4 Likes