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:
parent
171c3659f8
commit
fe6fe8ea52
@ -48,6 +48,7 @@ void setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
enum class State : uint8_t {
|
enum class State : uint8_t {
|
||||||
|
Sleep,
|
||||||
Idle,
|
Idle,
|
||||||
Menu,
|
Menu,
|
||||||
Counting,
|
Counting,
|
||||||
@ -64,6 +65,12 @@ void loop() {
|
|||||||
auto event = button.event(debounce.event(buttonPressed));
|
auto event = button.event(debounce.event(buttonPressed));
|
||||||
|
|
||||||
switch(state) {
|
switch(state) {
|
||||||
|
case State::Sleep:
|
||||||
|
if(buttonPressed) {
|
||||||
|
digitalWrite(DISPLAY_ENABLE, 0);
|
||||||
|
state = State::Idle;
|
||||||
|
timeout = millis();
|
||||||
|
}
|
||||||
case State::Idle:
|
case State::Idle:
|
||||||
if(event == ButtonEvent::Press) {
|
if(event == ButtonEvent::Press) {
|
||||||
state = State::Slowing;
|
state = State::Slowing;
|
||||||
@ -72,6 +79,9 @@ void loop() {
|
|||||||
timeout = millis();
|
timeout = millis();
|
||||||
} else if(event == ButtonEvent::DoublePress) {
|
} else if(event == ButtonEvent::DoublePress) {
|
||||||
state = State::Menu;
|
state = State::Menu;
|
||||||
|
} else if((uint16_t) millis() - timeout >= 10000) {
|
||||||
|
digitalWrite(DISPLAY_ENABLE, 1);
|
||||||
|
state = State::Sleep;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case State::Menu:
|
case State::Menu:
|
||||||
@ -79,6 +89,7 @@ void loop() {
|
|||||||
display.setDash();
|
display.setDash();
|
||||||
display.write();
|
display.write();
|
||||||
state = State::Idle;
|
state = State::Idle;
|
||||||
|
timeout = millis();
|
||||||
break;
|
break;
|
||||||
case State::Counting:
|
case State::Counting:
|
||||||
if(event == ButtonEvent::LongPress) {
|
if(event == ButtonEvent::LongPress) {
|
||||||
@ -95,6 +106,7 @@ void loop() {
|
|||||||
case State::Slowing:
|
case State::Slowing:
|
||||||
slowdown();
|
slowdown();
|
||||||
state = State::Idle;
|
state = State::Idle;
|
||||||
|
timeout = millis();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user