from machine import Pin
from utime import sleep_us,ticks_us
Trig=Pin(2,Pin.OUT)
Echo=Pin(3,Pin.IN)
def ultra():
Trig.low()
sleep_us(2)
Trig.high()
sleep_us(5)
Trig.low()
while Echo.value() == 0:
signal_off = ticks_us()
while Echo.value() == 1:
signal_on = ticks_us()
time_passed=signal_on-signal_off
distance = (time_passed*0.034)/2
print("The distance from the object is : ",distance,"cm.")
while True:
ultra()
sleep_us(1)