Debounce library for Arduino
#include <Debouncer.h>
int pin = 2;
int duration_ms = 50;
Debouncer debouncer(pin, duration_ms);
void setup()
{
// add from lambda
debouncer.subscribe(Debouncer::Edge::FALL, [](){
// do something on falling edge
});
debouncer.subscribe(Debouncer::Edge::RISE, [](){
// do something on rising edge
});
}
void loop()
{
debouncer.update();
}
AVR boards can have only two callbacks. (see examples/callbacks_uno_avr
)
debouncer.update();
Serial.print("current stable state = ");
Serial.println(debouncer.read());
if (debouncer.edge())
{
if (debouncer.rising())
{
Serial.print("rise");
}
if (debouncer.falling())
{
Serial.print("fall");
}
}
Debouncer debouncer(pin, duration); // default is active low (switch off = high)
Debouncer debouncer(pin, duration, Debouncer::Active::H); // active high (switch off = low)
Debouncer debouncer(pin, duration); // check duration after signel becomes stable (default)
Debouncer debouncer(pin, duration, Debouncer::Active::L, Debouncer::DurationFrom::TRIGGER); // check duration from first TRIGGER
MIT