import machine
import utime as time
from machine import Pin
# Rotary encoder input pins
clk = Pin(26, Pin.IN, Pin.PULL_DOWN)
dt = Pin(27, Pin.IN, Pin.PULL_DOWN)
leds = [4,0,2,15]
leds_pins = [Pin(i, Pin.OUT) for i in leds]
angle = 0
increment = 360/20
def rotary(pin):
global angle
if dt.value() != clk.value():
angle += increment
else:
angle -= increment
angle = angle % 360
print(angle)
clk.irq(handler = rotary, trigger = Pin.IRQ_FALLING)
last_angle = 0
while True:
if last_angle != angle:
num_leds = angle // 72
for led_pin in leds_pins:
led_pin.value(0)
for i in range(num_leds):
leds_pins[i].value(1)
last_angle = angle