// This is Button library Code
#ifndef button_h
#define button_h
#include "Arduino.h"
class Button
{
private:
uint8_t btn;
uint16_t state;
public:
void begin(uint8_t button) {
btn = button;
state = 0;
pinMode(btn, INPUT_PULLUP);
}
bool debounce() {
state = (state<<1) | digitalRead(btn) | 0xfe00;
return (state == 0xff00);
}
};
#endif
// Start her
Button btn1;
Button btn2;
int status = LOW;
void setup() {
btn1.begin(2);
btn2.begin(3);
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
// press button 1 to turn on the LED
if (btn1.debounce()) {
digitalWrite(LED_BUILTIN, HIGH);
}
// press button 2 to turn off the LED
if (btn2.debounce()) {
digitalWrite(LED_BUILTIN, LOW);
}
}