from machine import Pin,time_pulse_us
from time import sleep,sleep_us
echo = Pin(19, Pin.IN)
trigger = Pin(20, Pin.OUT)
while 1:
trigger.value(1)
sleep_us(10)
trigger.value(0)
timing=time_pulse_us(echo,1,1000000)
if timing<0:
print("error measurement")
else:
distance=timing/58
print("distance",distance,"cm")
sleep(0.5)