Table of Contents

ItimerSet()

ItimerSet() sets the interval and callback function, or the hardware timer to use.

ItimerSet command operation flow

bool ItimerSet(unsigned long intervalMs, void (*callback)())
bool ItimerSet(uint8_t timerNumber, unsigned long intervalMs, void (*callback)())

Commands

Command Arguments Return Value Operation
ItimerSet(intervalMs, callback) unsigned long intervalMs — Callback interval in ms. 0 is not allowed
void (*callback)() — Function in void functionName() form, called at each interval
bool Sets the interval and callback function, or the hardware timer to use.

Example

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"));
  }
}

Precautions

Built-in Commands in the Same Category

← Built-in Command List