Timing Functions

Several functions are available to help you control the timing or speed your program performs its actions.

This table can help you choose the appropriate feature.

FeatureSummaryTypical UsesGotchas
delay() Wait: 1 ms to 49.7 days Simple programs, easiest to use Can't do anything while waiting
Metro Library Recurring timing functions Schedule work at regular intervals Must repetitively call check() function
Variables that automatically increment General purpose: scheduling work, timeout waiting for input, etc. Variables must be outside functions. Avoid compare equals.
Wait: 1 µs to 16 ms Short delays for hardware response Interrupts can lengthen delay
Time since your code began General purpose Math & rollover handling required
IntervalTimer Function called at regular intervals Accessing hardware with precise timing Advanced interrupt programming is required
ARM Cycle Counter Counter increments with CPU clock Measure time with highest precision Only usable for short times
Time Library
TimeAlarms Lib.
Date & Time Keeping track of calendar time Extra hardware required to retain while power is off
RTC Functions Date & Time Keeping track of calendar time, direct RTC access without Time library Extra hardware required to retain while power is off