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