PyRaspBeta

← All practice problems

Raspberry Pi practice problem · Buttons & input

Left or right?

EasyBudget $5Python · gpiozero

A rotary encoder (KY-040): + to 3.3 V, GND to ground, CLK on GPIO17, DT on GPIO18. It has 20 detents (clicks) per turn.

Print one line per detent: Right for a clockwise click, Left for an anticlockwise one.

The test turns the knob clockwise to 54° at 1 s (3 clicks), then back to 18° at 3 s (2 clicks).

Tip: RotaryEncoder has when_rotated_clockwise and when_rotated_counter_clockwise.

More in Buttons & input