from lcdi2c import*
from utime import sleep
from machine import Pin,time_pulse_us
from time import sleep,sleep_us
echo = Pin(19, Pin.IN)
trigger = Pin(20, Pin.OUT)
cmd_wrt(0xc0+0)
string_write("LAB 6")
cmd_wrt(0xc0+8)
string_write("EMBEDDED")
def display(distance):
cmd_wrt(0x80)
string_write("dist:")
string_write(str(int(distance)))
string_write("cm")
def get_distance():
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)
return distance
lcd_start()
while 1:
display(get_distance())
sleep(0.2)