Language: EN

libreria-arduino-countdown

Arduino Countdown Library

The Countdown library implements a simple counter. The counter is initialized to a certain value using the StartValue variable. The current value of the counter is saved in the Value variable.

The counter has the Tick() method, which reduces the value of Value until it reaches zero. It also has the Reset method, which resets Value to the StartValue value.

Optionally, there is a callback function called OnFinish, which triggers when the counter reaches zero.

Apart from using a simple counter, such as a lap counter or an encoder, the main interest of the library is to use the Callback function to free up part of the code from the main flow of the program.

For example, we can use the counter to ignore the first N cycles of a signal to wait for it to stabilize, or to trigger a function every N occurrences of an event.

Finally, the functionality of the library is more interesting if we combine it with other libraries such as AsyncTask, MultiTask, StateMachine, or PetriNet.

User Manual

Constructor

The Countdown class is instantiated through one of its constructors.

Countdown(uint16_t startValue);

Countdown(uint16_t startValue, CountdownAction OnFinish);

Using Countdown

// Initial value of the counter
int16_t StartValue;

// Current value of the counter
uint16_t Value;

// Decreases the value of Value and triggers OnFinish if Value == 0
void Tick();

// Resets the value of Value to StartValue
void Reset();

// Callback function triggered when Value == 0
CountdownAction OnFinish;

Examples

The Countdown library includes the following examples to illustrate its use.

  • Countdown: Example of using the Countdown class

Installation

  • Download the latest version from GitHub
  • Unzip the file
  • Copy to your libraries folder (usually My Documents\Arduino\libraries)
  • Restart the Arduino IDE

github-full