12 ToggleButton(
int pin) : pin_(pin), on_(
false), debounce_timestamp_(0), changed_(
false) {
13 pinMode(pin_, OUTPUT);
14 digitalWrite(pin_, LOW);
24 void Update(uint32_t time_now) {
25 if ((time_now - debounce_timestamp_) < 150) {
30 int val = Read_Internal();
31 changed_ = on_ != val;
37 if ((time_now - debounce_timestamp_) > 150) {
39 debounce_timestamp_ = time_now;
45 bool Read_Internal() {
48 bool on = (digitalRead(pin_) == HIGH);
51 pinMode(pin_, OUTPUT);
52 digitalWrite(pin_, LOW);
59 uint32_t debounce_timestamp_;
103 explicit CountingButton(
int but_pin) : button_(but_pin), curr_val_(0) {
104 debounce_timestamp_ = millis();
108 void Update(uint32_t time_now) {
109 bool clicked = mButton.clicked();
110 FASTLED_DBG(
"clicked: " << clicked);
111 bool val = Read() || mButton.clicked();
112 bool changed = val != on_;
116 debounce_timestamp_ = time_now;
124 if ((time_now - debounce_timestamp_) > 16) {
128 debounce_timestamp_ = time_now;
133 int curr_val()
const {
return curr_val_; }
137 return button_.Read();
143 unsigned long debounce_timestamp_;