Raspberry Pi practice problem · Buttons & input
Step dimmer
MediumBudget $4Python · gpiozero
Two buttons — Up on GPIO5, Down on GPIO6 (both to ground) — and an LED on GPIO18 dimmed with PWM.
The brightness has five steps: 0, 25, 50, 75, 100 %. It starts at 0 % (off). Each Up press goes one step up, each Down press one step down, and it stops at the ends (no wrapping).
The test presses Up 5 times (1.0–3.0 s), then Down once (4.5 s), then Down 4 times (5.5–7.0 s). The PWM duty on GPIO18 is checked.