from machine import Pin
import time
trig=Pin(5,Pin.OUT)
echo=Pin(4,Pin.IN)
led1=Pin(9,Pin.OUT)
led2=Pin(12,Pin.OUT)
while True:
trig.off
time.sleep_us(2)
trig.on()
time.sleep_us(2)
trig.off()
while echo.value()==0:
siga=time.ticks_us()
while echo.value()==1:
sigb=time.ticks_us()
tm=sigb-siga
d=(tm*0.0343)/2
if(d>50):
led1.value(1)
led2.value(0)
else:
led1.value(0)
led2.value(1)
print(d)
time.sleep(1)