Raspberry Pi practice problem · Buttons & input
Encoder menu
HardBudget $20Python · gpiozero
A menu driven by one knob. Parts:
- a rotary encoder: + to 3.3 V, CLK GPIO17, DT GPIO18, SW GPIO27 (internal pull-up)
- a 16×2 LCD at I²C address 0x27 (5 V, SDA/SCL)
- three LEDs: red on GPIO5, green on GPIO6, blue on GPIO13, all off at the start
The menu has three items, Red, Green, Blue. The LCD's first line shows the selected item after > , the second line its LED state, ON or OFF:
> Green
OFF
Turning clockwise selects the next item, anticlockwise the previous one; the selection stops at the ends (no wrapping: turning further past Red or Blue does nothing, and turning back moves at once). Clicking the knob toggles the selected LED. Keep the LCD up to date.
The test: click at 1.0 s; turn to 36° at 2.0 s (2 clicks); click at 3.0 s; turn to 18° at 4.0 s; turn to −36° at 5.0 s (3 clicks back); turn to −18° at 6.0 s (1 click forward).