Skip to content
Valentin Boulanger edited this page Dec 31, 2019 · 1 revision

What is the Arduino Interval Library ?

The Interval library for Arduino allows you to perform asynchronous actions with your Arduino board, using intervals.

Why use this library ?

You want to flash a LED. You will use the the delays like this :

digitalWrite(LED_BUILTIN, HIGH);
delay(500);
digitalWrite(LED_BUILTIN, LOW);
delay(500);

But you want also emit a sound with tone() while the LED is flashing. These two actions can't be done at the same time, because the delay() function is blocking. The program flashes the LED, stops, wait 500 ms and then emits the sound.

But you can do it at the same time !

The key is timing. In Arduino, we can get the number of milliseconds since the power up of the board (millis ()function). By declaring an interval and a timer in the loop, we can check if the interval has been exceeded since the last action. If this is the case, an action is executed. Otherwise, the program continues and rechecks each time. During this time the counter increments.

This library allows you to do this easily and quickly !