Raspberry Pi practice problem · Buttons & input
Double-click
MediumBudget $6Python · gpiozero
A button on GPIO27 (to ground), a green LED on GPIO17 and a red LED on GPIO22.
- a double click — a second press starting within 0.4 s of releasing the first — toggles the red LED
- a single click — no second press within 0.4 s — toggles the green LED
So a single click can only be decided once the 0.4 s have passed. Both LEDs start off.
The test clicks (0.1 s each) at 1.0 s; at 2.5 s and 2.75 s (a double); and at 4.0 s.