Go Down

Topic: Seconds function? (Read 410 times) previous topic - next topic

Skywolf

Hello!

My Arduino code is full of stuff, including delays. In this, I want a second counter to be running from when the script starts. Is there any function I could use that does this, as I can't have it in my void loop due to many other delays?

Thanks!

el_supremo

millis() returns the number of milliseconds elapsed since your sketch started.

Pete

pYro_65

There are provided functions millis, and micros.
Check the Arduino reference http://arduino.cc/en/Reference/HomePage

Also load up the 'blink without delay' example code in the IDE to see how you can cause events to happen after a certain time rather than delaying.

There are many topics covering the many ways of managing multiple tasks, tons are here on the forum.


liudr

You can do a shortcut like:

#define seconds() (millis()/1000)

Of course this seconds counter wraps around in 49 days just like the millis() wraps around in 49 days.

Skywolf


Go Up