Browse Source

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.
master
Klemens Schölhorn 1 year ago
parent
commit
fe6fe8ea52
1 changed files with 12 additions and 0 deletions
  1. 12
    0
      code/code.ino

+ 12
- 0
code/code.ino View File

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

Loading…
Cancel
Save