-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbutton_indicator.cpp
38 lines (30 loc) · 1.06 KB
/
button_indicator.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// button_indicator.cpp
// github.com/jacoblukewood/ems
// Copyright 2020 Jacob Wood
#include "button_indicator.h"
#include <Arduino.h>
#include "utility.h"
ButtonIndicator::ButtonIndicator(int const pin_input, int const debounce, Indicator* indicator_for_button, Indicator* contrasting_indicator)
: indicator_(indicator_for_button)
, contrasting_indicator_(contrasting_indicator)
, Button(pin_input, debounce, indicator_for_button)
{ }
void ButtonIndicator::Refresh(void) {
bool const is_pressed = utility::IsDigitalInputHigh(kPinInput);
if (utility::IntervalPassed(time_last_pressed_, kDebounce)) {
if(is_pressed) {
time_last_pressed_ = millis();
if(!was_pressed_last_refresh_) {
if(indicator_->IsOn()) {
indicator_->Off();
} else {
indicator_->On();
contrasting_indicator_->Off();
}
}
was_pressed_last_refresh_ = true;
} else {
was_pressed_last_refresh_ = false;
}
}
}