ItimerSet() sets the interval and callback function, or the hardware timer to use.
bool ItimerSet(unsigned long intervalMs, void (*callback)())
bool ItimerSet(uint8_t timerNumber, unsigned long intervalMs, void (*callback)())
| Command | Arguments | Return Value | Operation |
|---|---|---|---|
ItimerSet(intervalMs, callback) | unsigned long intervalMs — Callback interval in ms. 0 is not allowedvoid (*callback)() — Function in void functionName() form, called at each interval | bool | Sets the interval and callback function, or the hardware timer to use. |
This uses the default callback timer (Timer2). The callback changes only a flag; serial output runs in loop().
volatile bool tick = false; void onTimer() { tick = true; } void setup() { Serial.begin(115200); if (!ItimerSet(1000, onTimer)) return; // Configure a 1 s callback on the default hardware timer. ItimerStart(); // Start the configured callback timer. } void loop() { if (tick) { noInterrupts(); tick = false; interrupts(); Serial.println(F("tick")); } }
delay(), Serial, I2C or SPI in it.tone() or PWM output that uses Timer2.