Skip to content

Instantly share code, notes, and snippets.

@piotr-piatkowski
Created June 7, 2022 17:19
Show Gist options
  • Save piotr-piatkowski/d1c7ae151e5c9e314f30217e52882796 to your computer and use it in GitHub Desktop.
Save piotr-piatkowski/d1c7ae151e5c9e314f30217e52882796 to your computer and use it in GitHub Desktop.
long next_state_change = 0;
long state = -1;
void loop() {
if(digitalRead(PIN_BUTTON) == LOW) {
state = 5;
// it will start counting after releasing button
next_state_change = millis() + 10000;
}
else if (millis() >= next_state_change) {
if (state == 5) {
state = 0;
}
else {
state = (state + 1) % 4;
}
next_state_change = millis() + 1500;
}
switch(state) {
case 0:
// ....
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment