Time
millis()
Returns the number of milliseconds since the device began running the current program. This number will overflow (go back to zero), after approximately 49 days.
unsigned long time = millis();
// EXAMPLE USAGE
SerialLogHandler logHandler;
void setup()
{
}
void loop()
{
unsigned long time = millis();
//prints time since program started
Log.info("millis=%lu", time);
// wait a second so as not to send massive amounts of data
delay(1000);
}
Note: The return value for millis is an unsigned long, errors may be generated if a programmer tries to do math with other data types such as ints.
Instead of using millis()
, you can instead use System.millis()
that returns a 64-bit value that will not roll over to 0 during the life of the device.