btnSDebouncing.h is a header only lib that implements simple software debouncing for push buttons.
In your file where a button will be used:
#define BTNSDEBOUCINH_H
#include "btnSDebouncing.h"
A button data type and a function to read the button.
Structure containing button data, where:
- int pin: The board pin where the button is connected
- int state: The state of the button,
HIGH
orLOW
- int lastState: The last state of the button,
HIGH
orLOW
- unsigned long lastDebounceTime: The last time of the boucing, initialize with
0
;
Function that performs button reading without bouncing
/*! @brief button reading without bouncing
* @param [Button] *btn - The adress of the button data
* @param [unsigned long] debounceDelay - The delay of the boucing, if pass NULL the default is 50 ms
* @return bool
*/
bool readDButton(Button *btn, unsigned long debounceDelay);
if the button is presses, return true