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() {
48 48
 }
49 49
 
50 50
 enum class State : uint8_t {
51
+    Sleep,
51 52
     Idle,
52 53
     Menu,
53 54
     Counting,
@@ -64,6 +65,12 @@ void loop() {
64 65
     auto event = button.event(debounce.event(buttonPressed));
65 66
 
66 67
     switch(state) {
68
+        case State::Sleep:
69
+            if(buttonPressed) {
70
+                digitalWrite(DISPLAY_ENABLE, 0);
71
+                state = State::Idle;
72
+                timeout = millis();
73
+            }
67 74
         case State::Idle:
68 75
             if(event == ButtonEvent::Press) {
69 76
                 state = State::Slowing;
@@ -72,6 +79,9 @@ void loop() {
72 79
                 timeout = millis();
73 80
             } else if(event == ButtonEvent::DoublePress) {
74 81
                 state = State::Menu;
82
+            } else if((uint16_t) millis() - timeout >= 10000) {
83
+                digitalWrite(DISPLAY_ENABLE, 1);
84
+                state = State::Sleep;
75 85
             }
76 86
             break;
77 87
         case State::Menu:
@@ -79,6 +89,7 @@ void loop() {
79 89
             display.setDash();
80 90
             display.write();
81 91
             state = State::Idle;
92
+            timeout = millis();
82 93
             break;
83 94
         case State::Counting:
84 95
             if(event == ButtonEvent::LongPress) {
@@ -95,6 +106,7 @@ void loop() {
95 106
         case State::Slowing:
96 107
             slowdown();
97 108
             state = State::Idle;
109
+            timeout = millis();
98 110
             break;
99 111
     }
100 112
 }

Loading…
Cancel
Save