from machine import Pin,PWM,RTC
from hcsr04 import HCSR04
import time
servo = PWM(Pin(18, mode=Pin.OUT))
servo.freq(50)
red=Pin(15,Pin.OUT)
green=Pin(2,Pin.OUT)
buzz=PWM(Pin(4,Pin.OUT))
sensor1 = HCSR04(trigger_pin=5, echo_pin=19, echo_timeout_us=10000)
sensor2 = HCSR04(trigger_pin=21, echo_pin=22, echo_timeout_us=10000)
while True:
distance1 = sensor1.distance_cm()
distance2 = sensor2.distance_cm()
print(distance1)
print(distance2)
time.sleep(1)
if distance1<=100:
servo.duty(76)
red.value(1)
green.value(0)
buzz.freq(1000)
else:
servo.duty(26)
red.value(0)
green.value(1)
buzz.freq(50)