from machine import Pin, PWM
from time import sleep
from math import floor

pwm = PWM(Pin(15))
pwm.freq(50)
duty = 0
pwm.duty_u16(duty)
sleep(0.1)

min_duty = 1700
max_duty = 10250
min_degrees = 0
max_degrees = 180

def degrees_to_duty(degrees):
 duty_step = ((max_duty - min_duty) / max_degrees)
 if degrees > max_degrees:
 degrees = max_degrees
 elif degrees < min_degrees:
 degrees = min_degrees
 duty = floor((duty_step * degrees)+ min_duty)
 if duty > max_duty:
 duty = max_duty
 elif duty < min_duty:
 duty = min_duty
 return duty

while True :
    duty = degrees_to_duty(0)
    pwm.duty_u16(duty)
    sleep(1)
    duty = degrees_to_duty(45)
    pwm.duty_u16(duty)
 sleep(1)
 duty = degrees_to_duty(90)
 pwm.duty_u16(duty)
 sleep(1)
 duty = degrees_to_duty(135)
 pwm.duty_u16(duty)
 sleep(1)
 duty = degrees_to_duty(180)
 pwm.duty_u16(duty)
 sleep(1)
BOOTSELLED1239USBRaspberryPiPico©2020RP2-8020/21P64M15.00TTT