//https://roboticsbackend.com/arduino-object-oriented-programming-oop/ #ifndef MY_BUTTON_H #define MY_BUTTON_H #include 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