ESP8266 WiFi Client
Loading...
Searching...
No Matches
Metronome Class Reference

The metronome. More...

#include <metronome.hpp>

Public Member Functions

 Metronome (int cycleDuration, bool skipMissedCycles=true)
 Constructor. *.
 
auto waitForNextCycle () -> void
 

Detailed Description

The metronome.

A helper class that let's you manage (somewhat) constant durations of your loop() function. Define a cycleDuration and call waitForNextCycle() at the end of your loop. Easy, isn't it? :)

Constructor & Destructor Documentation

◆ Metronome()

Metronome::Metronome ( int cycleDuration,
bool skipMissedCycles = true )
inline

Constructor. *.

Parameters
cycleDurationThe duration of one cycle of the loop.
skipMissedCyclesIn case a cycle has been missed - due to stuff happening within the loop taking more time than the defined cycle duration - this bool defines whether the missed cycle should be skipped or not. In this case true will make metronome's waitForNextCycle just wait until the next regular cycle, thereby skipping at least one cycle, whereas false will make metronome's waitForNextCycle return immediately and thereby trigger the next iteration of the loop in order to make up the delay.
Warning
Using skipMissedCycles = false in conjunction with a loop that usually takes more time than cycleDuration will lead to a growing delay that can never be made up.

Member Function Documentation

◆ waitForNextCycle()

void Metronome::waitForNextCycle ( ) -> void

Blocks until the next cycle starts. Might return immediately if the Metronome has been configured NOT to skip missed cycles ( skipMissedCycles = false ). See Metronome(int, bool).


The documentation for this class was generated from the following files: