Skip to content

TimMathias/Debouncer

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Debouncer

Debounce library for Arduino

Usage

Callbacks

#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();
}

Limitation for AVR boards (like Uno and Mega)

AVR boards can have only two callbacks. (see examples/callbacks_uno_avr)

Other APIs

    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");
        }
    }

Active Low / High

Debouncer debouncer(pin, duration); // default is active low (switch off = high)
Debouncer debouncer(pin, duration, Debouncer::Active::H); // active high (switch off = low)

Debounce Mode

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

LICENSE

MIT

About

Debounce library for Arduino

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C++ 98.9%
  • C 1.1%