Untitled

 avatar
unknown
plain_text
a month ago
572 B
3
Indexable
from gpiozero import RotaryEncoder, Button
from signal import pause

# Set up the rotary encoder on GPIO 17 (CLK) and GPIO 27 (DT)
encoder = RotaryEncoder(a=17, b=27)

# Set up the button on GPIO 22
button = Button(22)

def rotated_left():
    print("⏪ Rotated left")

def rotated_right():
    print("⏩ Rotated right")

def button_pressed():
    print("🔘 Button pressed")

encoder.when_rotated_clockwise = rotated_right
encoder.when_rotated_counter_clockwise = rotated_left
button.when_pressed = button_pressed

print("🌀 Turn or press the dial to test!")
pause()
Editor is loading...
Leave a Comment