Raspberry Pi practice problem · Buttons & input
Fix the bounce
MediumBudget $2Python · gpiozero
The starter code polls a button on GPIO27 and counts falling edges — but this button is very bouncy (about 10 ms of chatter on every press and release), so one press is counted several times.
Fix main.py so each press counts exactly once, printing the running total after each press:
Count: 1
Count: 2
The circuit is fine as it is. Debounce however you like: accept a new level only after it has been stable for ~20 ms, or use gpiozero's bounce_time. The test presses five times (0.2 s each, from 1.0 s, every 0.6 s).