Interval - Arduino Library for Interval Timing
The design concept of an Arduino application is based on two main methods – setup() and loop(), in which the program runs continuously. For more convenient handling of periodic processes, I have written a simple library that allows these tasks to be executed in a very elegant way.
The Interval library creates timer objects and allows you to control them using the following methods.
set
The set method is used to set the timeout and define the start of the timing.
expired
The expired method is used to check whether the set interval has already elapsed.
setOneshot
The setOneshot method configures the timer for a one-shot run. After it expires, the timer is stopped.
setPeriodic
The setPeriodic method configures the timer for a periodic run. After expiration, the timer is automatically reset to the specified time.
reload
The reload method restarts the timer with the last specified time constant.
elapsed
The elapsed method returns the time that has elapsed since the timer started.
remains
The remains method returns the time remaining until the timer finishes, or until a new cycle begins.
An interesting feature is that the library correctly handles the overflow of the internal millisecond counter, so there is no risk of incorrect timing even during very long operation periods.