Skip to Content
Circuitera

Choose a stable window for an Arduino pushbutton

Pretend LOW first appears at 10 ms, bounces HIGH at 14 ms, then returns LOW at 17 ms.

0 of 3 complete · Progress saved on this device

Work out the example

Pretend LOW first appears at 10 ms, bounces HIGH at 14 ms, then returns LOW at 17 ms. Restart the quiet-time clock at each raw transition. Count a press only when the candidate has remained unchanged for the requested interval.

At what time can the press first become stable, in ms?

Decide what to check next

With a 20 ms window and continuous sampling, the earliest accepted low is 37 ms. Slow polling can recognize it later. On real hardware choose the interval against captured behavior and the acceptable response delay.

Compare with the serial result

It prints 37 for the final stable segment.

Open the exact Uno example

It prints 37 for the final stable segment.

void setup() {
  Serial.begin(9600);
  const uint32_t lastChange=17, window=20;
  for (uint32_t t=17; t<=40; ++t) {
    if (t-lastChange >= window) { Serial.println(t); break; }
  }
}
void loop() {}

Verified with [email protected] on Uno R3 (2026-12-05 UTC). This check did not use physical hardware.

Continue learning

Sources