I want to use millis() as a global timer, however when it rolls over to zero, how do I handle that ?
Cheers
K
I want to use millis() as a global timer, however when it rolls over to zero, how do I handle that ?
Cheers
K
What do you mean by "global timer"?
You could search the forum. There have been many threads on the subject. There is also an article on the playground.
I did search the site, but obviuosly not deep enough
Found the answer here
http://www.arduino.cc/playground/Code/TimingRollover
Cheers
K
Use unsigned longs to track time and use a math operation in the compare.
if ( now - start >= desired_interval ) {
/* do whatever */
}
You won't have rollover problems, the answer will be positive and correct up to the unsigned long limit.