Millis

From Pinguino
Jump to: navigation, search

Name

millis

Description

This function returns the time elapsed since the begining of the program (or the last timer overflow or reset).

When the program starts an internal timer counter is initialized to 0. The timer counter is a 32 bit integer variable that is incremented each millisecond. The timer counter overflows everytime it reaches 4,294,968,295 (2^32 - 1) which will happen approximately once every 49 days. The millis() function returns the current value of the timer counter.

Since
Beta 5

Syntax

u32 millis(void)
Parameters
[None]
Returns/Output
Returns the time elapsed in milliseconds since the user program was started.
Control
To reset the timer counter:
_millis = 0;

Example

void setup()
{
pinMode(0,OUTPUT);
digitalWrite(0,LOW);
}

void loop()
{
if (millis()>1000) digitalWrite(0,HIGH);  // light the led after 1 second

if (millis()>2000) _millis=0;  // reset the millis() counter after 2 seconds
}

Bugs & Limitations

Up till X.3 r412 (14 May 2012), the timer for P8 used a variable of data type long, a 32 bit signed data type, so approximately 25 days after the program start, the timer counter would overflow to a large negative number. From X.3 r412 the P8 data type was changed to u32, the same as for P32.

See also

Comments