from machine import PWM , Pin ,ADC
import time
adc_pin=Pin(26,Pin.IN)
pot=ADC(adc_pin)
Servo_pin=Pin(27,Pin.OUT, value =0)
servo =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 # c'est fonction pour donner les angles de servo
def rotate (angle,servo):
duty=int(map(angle ,0,180,1500,8000))
servo.duty_u16(duty)
while 1:
'''duty=int(map(45,0,180,1500,8000))
servo.duty_u16(duty)
time.sleep(1)
duty=int(map(130,0,180,1500,8000))
servo.duty_u16(duty)
time.sleep(1) # lfa9rra hathi bech na3mlhom fi fonction isimha rotate
'''
'''rotate (0,servo)
time.sleep(1)
rotate(180,servo)
time.sleep(1)
'''
pot_signal=pot.read_u16()
angle=int(map(pot_signal,0,65535,0,180))
rotate(angle,servo)
time.sleep_ms(20)