skip navigational linksPJRC
Shopping Cart Checkout Shipping Cost Download Website
Home Products Teensy Blog Forum
You are here: Teensy Teensyduino Timing millis

PJRC Store
Teensy 3.6, $29.25
Teensy 3.5, $24.25
Teensy 3.2, $19.80
Teensy LC, $11.65
Teensy 2.0, $16.00
Teensy++ 2.0, $24.00
Teensy
Main Page
Hardware
Getting Started
How-To Tips
Code Library
Projects
Teensyduino
Reference

Timing Functions

System Time: millis() & micros()

You can get the total time since your program started, in milliseconds using millis(), or in microseconds using micros().

These return a number between 0 to 4294967295. When they reach the maximum, they roll back over to 0. For millis, that's approximately 49.7 days. For micros, that's 1 hour, 11 minutes, 34.967295 seconds. When computing time differences, care should be taken to handle the roll over case. An example can be found in File > Examples > 2.Digital > BlinkWithoutDelay.

Internally, elapsedMillis and elapsedMicros use millis and micros. They handle roll over automatically, and are much easier to use.

TODO: add some examples

TODO: section about getting the math right, #1: 32 bit unsigned long, #2: handling rollover