from machine import Pin, PWM
from hcsr04 import HCSR04
import time
sensor = HCSR04(trigger_pin=12, echo_pin=14, echo_timeout_us=1000000)
servo = PWM(Pin(18, Pin.OUT), freq=50)
# while True:
# distance = sensor.distance_cm()
# print(f"Distance: {distance}")
# if distance > 100:
# servo.duty(74)
# else:
# servo.duty(24)
for t in range(24, 123):
distance = sensor.distance_cm()
print(f"Distance: {distance}")
if distance > 100:
servo.duty(74)
elif distance <= 100:
servo.duty(24)
# servo.duty(24)
# time.sleep(1)
# servo.duty(int((123 + 24) / 2))
# time.sleep(1)
# while True:
# servo.duty(24)
# time.sleep(1)
# servo.duty(int((123 + 24) / 2))
# time.sleep(1)