Distinguish short and long Arduino button presses on release
Record a timestamp at the debounced press edge.
0 of 3 complete · Progress saved on this device
Work out the example
Record a timestamp at the debounced press edge. On the release edge subtract the start timestamp. With a threshold of 600 ms, a measured duration equal to 600 counts as long when the comparison uses >=.
Decide what to check next
Decide whether an action fires on release or once at the threshold while still held. These are separate state machines. In the release-based version there is one decision per completed press.
Compare with the serial result
The fixed timestamp pair prints long.
Open the exact Uno example
The fixed timestamp pair prints long.
void setup() {
Serial.begin(9600);
const uint32_t started=120, released=720;
Serial.println(released-started >= 600 ? "long" : "short");
}
void loop() {}Verified with [email protected] on Uno R3 (2026-12-05 UTC). This check did not use physical hardware.