from machine import Pin, PWM
from utime import sleep_ms
# Connect servo to pin 21 using PWM
servo1 = PWM(Pin(21), freq=50)
BTN = Pin(17, Pin.IN, Pin.PULL_UP)
while True:
pressed = (BTN.value() == 0)
if pressed:
# Move servo to the left
servo1.duty(40) # Small number = left
else:
# Move servo to the right
servo1.duty(110) # Big number = right
sleep_ms(20)