from machine import Pin, ADC
import utime as time
import dht 
from lcd1602 import LCD

sensor = dht.DHT22(Pin(22))
#sensor = dht.DHT11(Pin(22))

lcd = LCD()

an = ADC(Pin(28))
led = Pin(2, Pin.OUT)

temp = 0  # Global variable for temperature
temperature = 0  # Global variable for analog temperature

def readDHT():
    global temp
    time.sleep(1)
    sensor.measure()
    temp = sensor.temperature()
    hum = sensor.humidity()
    lcd.write(0, 0, "T:" + str(temp) + "C  H:" + str(hum) + "%")

def readAn():
    global temperature
    anVal = an.read_u16()
    temperature = anVal / 65535 * 100
    temperature_str = "{:.1f}".format(temperature)  
    lcd.write(0, 1, "T.Temp: " + temperature_str + "C")

while True:
    readDHT()
    readAn()
    print(str(temp))  # Print the temperature for debugging
    if temp > temperature:
        led.value(1)
    else:
        led.value(0)
BOOTSELLED1239USBRaspberryPiPico©2020RP2-8020/21P64M15.00TTT