Debounce is a debouncing library for Particle. Debounce is based on Bounce2 orginally written by Thomas Ouellet Fredericks with contributions from: Eric Lowry, Jim Schimpf and Tom Harkaway. Debounce was modified for Particle by David Washington.
#include "Debounce/Debounce.h"
Debounce debouncer = Debounce();
void setup() {
pinMode(D7, OUTPUT);
debouncer.attach(D0, INPUT_PULLUP);
debouncer.interval(20); // interval in ms
}
void loop() {
debouncer.update();
if (debouncer.read() == LOW) {
digitalWrite(D7, HIGH);
} else {
digitalWrite(D7, LOW);
}
}
Instantiates a Debounce object.
Sets the debounce time in milliseconds.
Sets the pin and matches the internal state to that of the pin. Only attach the pin once you have done setting the pin up (for example setting an internal pull-up).
Because Debounce does not use interrupts, you have to "update" the object before reading its value and it has to be done as often as possible (that means to include it in your loop()). The update() method updates the object and returns true (1) if the pin state changed. False (0) if not. Only call update() once per loop().
Reads the updated pin state.
Returns true if pin signal transitions from high to low.
Returns true if signal transitions from low to high.
By default, the Bounce library uses a stable interval to process the debouncing. This is simpler to understand and can cancel unwanted noise.
By defining "#define BOUNCE_LOCK_OUT" in "Bounce.h" you can activate the alternative debouncing method. This method is a lot more responsive, but does not cancel noise.