Go Down

Topic: Usimg millis() as a global timer (Read 644 times) previous topic - next topic

fiddler

I want to use millis() as a global timer, however when it rolls over to zero, how do I handle that ?


Cheers
K

Coding Badly


What do you mean by "global timer"?

dxw00d

You could search the forum. There have been many threads on the subject. There is also an article on the playground.

fiddler

I did search the site, but obviuosly not deep enough :-)

Found the answer here
http://www.arduino.cc/playground/Code/TimingRollover

Cheers
K

GoForSmoke

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.

Nick Gammon on multitasking Arduinos:
1) http://gammon.com.au/blink
2) http://gammon.com.au/serial
3) http://gammon.com.au/interrupts

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy