GPIO Interrupts Explained
Polling a GPIO pin in a while True loop burns a CPU core to notice a button
press. Interrupts flip the relationship: the kernel taps you on the shoulder when the edge
you care about happens.
from gpiozero import Button
button = Button(17, bounce_time=0.05)
button.when_pressed = lambda: print("edge detected, zero polling")
The debounce trap
Mechanical switches bounce for 1–20ms. Without bounce_time, one press fires
your callback a dozen times. Hardware debounce (an RC filter) is better than software when
timing matters — a 10kΩ resistor and 100nF cap cost less than the bug report.