from machine import Pin, PWM, ADC
from time import sleep
sleep (0.1)
print ("begin")
servoPin = PWM(Pin(28))
# даёт сигнал каждые 20 мс, т.е. 50 Гц
servoPin.freq(50)
pot = ADC(Pin(26))
def servo(degrees):
# limit degrees beteen 0 and 180
if degrees > 180: degrees=180
if degrees < 0: degrees=0
# set max and min duty
maxDuty=9000
minDuty=1000
# new duty is between min and max duty in proportion to its value
koeff = (maxDuty-minDuty) / 180
newDuty=minDuty+ koeff * degrees
# servo PWM value is set
servoPin.duty_u16(int(newDuty))
while True:
potValue = pot.read_u16()
angle = int(potValue * 180 / 65535)
print(potValue, angle)
servo(angle)
sleep (0.2)