#include class ButtonController { private: int pin; int new_value; int old_value = HIGH; public: ButtonController(int pin){ this->set_pin(pin); }; void configure_pins(){ pinMode(this->pin, INPUT_PULLUP); } void set_pin(int pin){ this->pin = pin; } void read(){ this->new_value = digitalRead(this->pin); } bool value_changed(){ return (this->new_value != this->old_value); } bool is_pressed(){ if(this->value_changed()){ bool is_pressed = (this->new_value == LOW); this->old_value = this->new_value; return is_pressed; } return this->new_value == LOW; } };