You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
1007 B

//https://roboticsbackend.com/arduino-object-oriented-programming-oop/
#ifndef MY_BUTTON_H
#define MY_BUTTON_H
#include <Arduino.h>
class Button {
private:
byte pin;
// Button timing variables
int debounce = 20; // ms debounce period to prevent flickering when pressing or releasing the button
int holdTime = 500; // ms hold period: how long to wait for press+hold event
int longHoldTime = 1500; // ms long hold period: how long to wait for press+hold event
// Button variables
boolean buttonVal = HIGH; // value read from button
boolean buttonLast = HIGH; // buffered value of the button's previous state
long downTime = -1; // time the button was pressed down
long upTime = -1; // time the button was released
boolean ignoreUp = false; // whether to ignore the button release because the click+hold was triggered
public:
Button(byte pin);
void init();
byte getState();
};
#endif