The Counter library provides a way of counting rising edges until a defined preset value.
- The Arduino IDE 1.8.0 or higher
- The Industrial Shields Arduino boards (optional, used in the examples)
- Download the library from the GitHub as a "ZIP" file.
- From the Arduino IDE, select the downloaded "ZIP" file in the menu "Sketch/Inlcude library/Add .ZIP library".
- Now you can open any example from the "File/Examples/Counter" menu.
#include <Counter.h>
Counter C(100);
The Counter
returns HIGH when the internal counter is equal to the preset value.
int up = digitalRead(I0_0);
int down = digitalRead(I0_1);
int reset = digitalRead(I0_2);
if (C.update(up, down, reset, preset) == HIGH) {
// Enter here when the counter is equal to 100
// The counter counts up when I0.0 rises
// The counter counts down when I0.1 rises
// The counter is set to zero when I0.2 is HIGH
}