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.
Este commit está contenido en:
Klemens Schölhorn 2018-02-19 23:37:10 +01:00
padre 171c3659f8
commit fe6fe8ea52
Se han modificado 1 ficheros con 12 adiciones y 0 borrados

Ver fichero

@ -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;
}
}