from hcsr04 import HCSR04
from machine import Pin, PWM
from time import sleep
sensor1 = HCSR04(trigger_pin=5, echo_pin=18, echo_timeout_us=10000)
sensor2 = HCSR04(trigger_pin=13, echo_pin=12, echo_timeout_us=10000)
buz = PWM(Pin(2, Pin.OUT))
while True:
distance1 = sensor1.distance_cm()
distance2 = sensor2.distance_cm()
print('Distance1:', distance1, 'cm')
print('Distance2:', distance2, 'cm')
if distance1<10:
buz.freq(4000)
if distance2<50:
buz.freq(1000)
else:
buz.freq(45)