Pages: [1]   Go Down
Author Topic: Seconds function?  (Read 325 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

Offline Offline
Edison Member
*
Karma: 43
Posts: 1551
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pete
Logged

Where are the Nick Gammons of yesteryear?

North Queensland, Australia
Offline Offline
Edison Member
*
Karma: 64
Posts: 2100
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Logged


Central MN, USA
Offline Offline
Tesla Member
***
Karma: 72
Posts: 7171
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Perfect. Thank you!
Logged

Pages: [1]   Go Up
Jump to: