from machine import Pin
from time import sleep
from hcsr04 import HCSR04
but_1 = Pin(15, Pin.IN, Pin.PULL_UP)
led_1 = Pin(2, Pin.OUT)
senso = HCSR04(trigger_pin = 5, echo_pin = 18)
while True:
but_sta1 = but_1.value()
if but_sta1 == 0:
distance = senso.distance_cm()
for i in range(distance):
led_1.value(1)
sleep(0.1)
led_1.value(0)
sleep(0.1)