SimpleTimer
SimpleTimer copied to clipboard
millis() wrap
After 49 days of running, millis() wraps and SimpleTimer logic will be broken (will fire at wrong time). Check for this condition is needed.
for example:
if (current_millis - prev_millis[i] >= delays[i]) {
if: prev_millis[0] == 4,294,967,290 (just 5 mills from wrap over) current_millis == 1 (just after wrap over)
"if" statement above will be satisfied for almost any delays[0] value. this will lead to timer being fired pre-maturely
The solution is to use "unsigned long" for all variables in the equation that checks the elapsed time against the wanted expiry time (if (current_millis - prev_millis[i] >= delays[i]) {). So delays must also be unsigned long. See also: http://playground.arduino.cc/Code/TimingRollover.