from machine import Pin, PWM, ADC
import time
servo = PWM(Pin(12), freq=50)
pot = ADC(Pin(35))
pot.atten(ADC.ATTN_11DB)
def map(x, in_min, in_max, out_min, out_max):
return int((x - in_min)*(out_max - out_min)/(in_max - in_min) + out_min)
while 1:
adc = pot.read()
print("pot:", adc, end=" >> ")
duty = map(adc, 0, 4095, 27, 120)
servo.duty(duty)
pos = map(duty, 27, 120, 0, 180)
print("Servo Position", pos)
time.sleep_ms(100)