PyRaspBeta

← All practice problems

Raspberry Pi practice problem · Buttons & input

Click the knob

EasyBudget $6Python · gpiozero

A rotary encoder's shaft is also a button: pressing it joins SW to ground.

Build: a rotary encoder with + on 3.3 V, GND on ground and SW on GPIO27 (CLK and DT can stay unconnected), plus an LED on GPIO22.

Program: each click of the knob toggles the LED. SW has no pull-up on the module, so turn on the Pi's internal one.

The test clicks the knob at 1.0 s, 2.5 s and 4.0 s.

More in Buttons & input