Skip to content

Instantly share code, notes, and snippets.

@Palatis
Last active January 10, 2017 11:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Palatis/d5f759db6ba604fbe80520e3e7c4615e to your computer and use it in GitHub Desktop.
Save Palatis/d5f759db6ba604fbe80520e3e7c4615e to your computer and use it in GitHub Desktop.
byte oldState = HIGH;
time_t downMillis = 0;
time_t lastTickMillis = 0;
void loop() {
byte state = digitalRead(BTN);
if (oldState != state) {
if (state == LOW) {
clock.tick(); // button just pressed, tick the first time...
lastTickMillis = downMillis = millis();
}
oldState = state;
}
if (state == LOW) {
if (millis() - downMillis < 2300) {
// within 2300ms (add 300ms buffer), tick every 1000ms.
if (millis() - lastTickMillis > 1000) {
clock.tick();
lastTickMillis = millis();
}
} else {
// after 2300ms, tick every 500ms.
if (millis() - lastTickMillis > 500) {
clock.tick();
lastTickMillis = millis();
}
}
}
clock.draw(); // draw the clock
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment