from machine import PWM , Pin , ADC
import time
adc_pin =Pin(26 , Pin.IN)
pot = ADC(adc_pin)
servo_pin = Pin(14 , Pin.OUT , value = 0)
servo1 = PWM(servo_pin , 50 , duty = 0)
def map(x, in_min, in_max, out_min, out_max):
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min
def rotate(angle , servo):
duty = int(map(angle ,0 , 180 , 1500 , 8000))
servo.duty_u16(duty)
while 1 :
pot_signal = pot.read_u16()
angle = int(map(pot_signal ,0 , 65535 , 0, 180))
rotate(angle , servo1)
time.sleep_ms(20)
'''
ADC analog to digital Converter
1.7V 40000
DAC digital to analog Converter
40000 1.7 V
0 0V
65535 3.3V
'''