/*
Arduino | coding-help
robherc KV5ROB - Sunday, March 22, 2026 4:58 PM
state machine, yes, but maybe "detect tap" and "detect long-press"
would yield better google results
basic premise:
*/
const int myButton = 12;
const int PRESSED = LOW;
int lastState = HIGH;
unsigned long pressedMillis = 0;
void setup() {
Serial.begin(115200);
pinMode(myButton, INPUT_PULLUP);
}
void loop() {
if (digitalRead(myButton) == PRESSED) {
if (lastState != PRESSED) {
lastState = PRESSED;
pressedMillis = millis();
}
} //else {
if (lastState == PRESSED) {
if ((millis() - pressedMillis) > 350) {
Serial.println("You long-pressed!\n");
} else {
Serial.println("You tapped!\n\n");
}
lastState = !PRESSED;
}
//}
}