make the cycle pausable

This commit is contained in:
Felix Pankratz 2024-12-28 16:33:35 +01:00
parent b3026052c2
commit cd8f565e3e
2 changed files with 31 additions and 3 deletions

21
nametag/src/enums.cpp Normal file
View File

@ -0,0 +1,21 @@
#include "enums.h"
#include "constants.h"
DisplayStyle next_style(DisplayStyle style) {
switch(style) {
case Rain:
return Congress;
break;
case Congress:
return Supercomputer;
break;
case Supercomputer:
return Cyber;
break;
case Cyber:
return Flame;
break;
case Flame:
return Rain;
break;
}
}

View File

@ -20,6 +20,7 @@ Mode mode = HighVis;
DisplayStyle style = Rain; DisplayStyle style = Rain;
unsigned long last_switch; unsigned long last_switch;
bool cycling = true;
void setup(){ void setup(){
pinMode(ONBOARD_LED, OUTPUT); pinMode(ONBOARD_LED, OUTPUT);
@ -52,9 +53,8 @@ void setup(){
void loop() { void loop() {
matrix ->flipDMABuffer(); matrix ->flipDMABuffer();
matrix->clearScreen(); matrix->clearScreen();
//delay(25);
if (millis() - last_switch > CYCLE_TIME_MS) { if (cycling and millis() - last_switch > CYCLE_TIME_MS) {
// next style // next style
style = next_style(style); //DisplayStyle((style + 1) % (NumStyles - 1)); style = next_style(style); //DisplayStyle((style + 1) % (NumStyles - 1));
last_switch = millis(); last_switch = millis();
@ -76,8 +76,15 @@ void loop() {
} }
if(!digitalRead(NEXT_BUTTON)) { if(!digitalRead(NEXT_BUTTON)) {
style = next_style(style); unsigned long pressed_at = millis();
while(!digitalRead(NEXT_BUTTON)); // Wait for release while(!digitalRead(NEXT_BUTTON)); // Wait for release
// see if the button was held or tapped
if (millis() - pressed_at > 500) {
// todo
cycling = not cycling;
} else {
style = next_style(style);
}
} }
switch(style) { switch(style) {