from machine import ADC, PWM, Pin
import utime
# Set PWM on Pin 0 for controlling the servo motor
s = PWM(Pin(0))
s.freq(50) # Set frequency to 50 Hz for the servo
abc = ADC(2) # Read analog input from Pin 2
while True:
# Read the potentiometer value and map it to the range 0-180
pot = int(abc.read_u16() * 180 / 65535)
print(pot) # Print the mapped value
# Calculate the duty cycle for the servo based on the potentiometer
ton = (pot + 45) * 100000 / 9
s.duty_ns(int(ton)) # Set the duty cycle
utime.sleep_ms(200) # Wait for 200 milliseconds