from machine import Pin, PWM
import time
pwm_pin=PWM(Pin(14))
pwm_pin.freq(50)
#0.5 ms for 0 degree
#2.5ms for 180 degree
while True:
# 25 to 125 for 0 to 180 degree
for x in range(0,180,1):
y=(((2.5-0.5)/(180-0)*x+0.5)/20*1023)
pwm_pin.duty(int(y))
time.sleep_ms(500)
for x in range(180,0,-1):
y=(((2.5-0.5)/(180-0)*x+0.5)/20*1023)
pwm_pin.duty(int(y))
time.sleep_ms(500)