from machine import Pin
from time import sleep 
from hcsr04 import HCSR04

sensor= HCSR04(trigger_pin-4, echo_pin=15)
led1 = Pin(2, Pin.OUT)
led2 = Pin(5, Pin.OUT)
led3 = Pin(18, Pin.OUT)

while True:

distance = sensor.distance_cm() 
print('Distance: ', distance, cm') 
sleep(0.1)

if distance < 20:
    led1.on()

elif distance < 30:
    led1.on()
    led2.on() 
elif distance < 40:
    led1.on()
    led2.on()
    led3.on()
else:
    led1.off() 
    led2.off()
    led3.off()