Seconds function?


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?


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


There are provided functions millis, and micros. Check the Arduino reference

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.

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.

Perfect. Thank you!