from hcsr04 import HCSR04
from machine import Pin
from time import sleep
a = HCSR04(trigger_pin=4,echo_pin=5)
led = [Pin(2,Pin.OUT),Pin(19,Pin.OUT),Pin(18,Pin.OUT)]
while True:
b=a.distance_cm()
if b < 20:
led[0].on()
led[0].off()
elif 19 < b < 30:
for i in led[0:2]:
i.on()
sleep(0.5)
for i in led[0:2]:
i.off()
elif 29 < b <40:
for i in led:
i.on()
sleep(0.5)
for i in led:
i.off()