Disable led display after 10 seconds to save energy

Going to sleep and waking on an interrupt generated by the button would
save even more energy, but it our current chip unfortunately has problems
waking up reliably.
This commit is contained in:
Klemens Schölhorn 2018-02-19 23:37:10 +01:00
vecāks 171c3659f8
revīzija fe6fe8ea52
1 mainīti faili ar 12 papildinājumiem un 0 dzēšanām

Parādīt failu

@ -48,6 +48,7 @@ void setup() {
}
enum class State : uint8_t {
Sleep,
Idle,
Menu,
Counting,
@ -64,6 +65,12 @@ void loop() {
auto event = button.event(debounce.event(buttonPressed));
switch(state) {
case State::Sleep:
if(buttonPressed) {
digitalWrite(DISPLAY_ENABLE, 0);
state = State::Idle;
timeout = millis();
}
case State::Idle:
if(event == ButtonEvent::Press) {
state = State::Slowing;
@ -72,6 +79,9 @@ void loop() {
timeout = millis();
} else if(event == ButtonEvent::DoublePress) {
state = State::Menu;
} else if((uint16_t) millis() - timeout >= 10000) {
digitalWrite(DISPLAY_ENABLE, 1);
state = State::Sleep;
}
break;
case State::Menu:
@ -79,6 +89,7 @@ void loop() {
display.setDash();
display.write();
state = State::Idle;
timeout = millis();
break;
case State::Counting:
if(event == ButtonEvent::LongPress) {
@ -95,6 +106,7 @@ void loop() {
case State::Slowing:
slowdown();
state = State::Idle;
timeout = millis();
break;
}
}