#from lcd_library import LCD
from lcd import LCD1602
from machine import Pin,ADC
from time import sleep
ntc_pin=ADC(Pin(27)) # Assign/define temperature pin number
relay_pin=Pin(25,Pin.OUT) # Assign relay pin number (coil2_P2)
relay_pin=Pin(26,Pin.OUT) # Assign relay pin number (coil1_P1)
# Assign LCD with GPIO pins (modify for ESP32 if needed)
lcd=LCD1602(rs=4,en=5,d4=12,d5=13,d6=14,d7=15)
# Function to display real time temperature and humidity
#last_temp=None
#function to invert analog value
def invert_analog(value,max_value=61022):
return max_value-value
while True:
#raw values (7393 to 61022) & read temperature
temp_raw_val=ntc_pin.read_u16()
#invert the read temperature
inverted_temp_raw_val=invert_analog(temp_raw_val)
print(inverted_temp_raw_val)
#temp=[(raw_val-7393)*(72+12)/(61022-7393)]-12
#temp=int(((temp_raw_val-7393)*84/53629)-12) #temperature (-12 to 72'C) use ratio formula
#print(temp)
sleep(3)
# if temp != last_temp:
# lcd.clear()
# lcd.set_cursor(0,0)
# lcd.putstr(f"Temp: {temp:.1f} C")
# last_temp=temp
#while True:
# ldr_value=ldr_pin.value()
# if ldr_value==True:
# relay_pin.value(1)
# else:
# relay_pin.value(0)
# time.sleep_ms(700)
#const float BETA = 3950; // should match the Beta Coefficient of the thermistor
#int analogValue = analogRead(A0);
#float celsius = 1 / (log(1 / (1023. / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15;