from machine import Pin, PWM
from hcsr04 import HCSR04
from time import sleep
import utime
servo_180 = PWM(Pin(15))
servo_180.freq(50)
sensor = HCSR04(trigger_pin=2, echo_pin=3, echo_timeout_us=10000)
while True:
d =int(sensor.distance_cm())
if d >=20 and d<=25:
print('DSM')
duty = int((12.346*0*2 + 7777.8*0 + 700000))
servo_180.duty_ns(duty)
sleep(5)
else:
duty = int((12.346*90*2 + 7777.8*90 + 700000))
servo_180.duty_ns(duty)
print('Distance:', d, 'cm')
sleep(1)