from lcd import*
from machine import ADC,time_pulse_us
from time import sleep,sleep_us
from math import log
BETA = 3950
echo = Pin(19, Pin.IN)
trigger = Pin(22, Pin.OUT)
ntc = ADC(Pin(28))
lcd_start()
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 ")
cmd_wrt(0x80)
string_write("DIS:")
string_write(str(int(distance)))
string_write("cm")
if distance >10:
string_write(" FAR ")
else:
string_write(" NEAR")
def get_temp():
nilai=ntc.read_u16() #to get reading in digital voltage
celsius = 1 / (log(1 / (65535.00 / nilai - 1)) / BETA + 1.0 / 298.15) - 273.15;
print("temperature",celsius," ^C")
cmd_wrt(0xc0+0)
string_write("TEMP:")
string_write(str(int(celsius)))
string_write("^C")
if celsius >30:
string_write(" HOT ")
else:
string_write(" COLD")
lcd_start()
while 1:
get_distance()
get_temp()
sleep(0.2)