# HISYAM BIN SHAMSUDDIN (CB230148)
from machine import Pin, PWM, I2C
from time import sleep
from dht import DHT22
from lcd1602 import LCD
from machine import Pin, ADC
led0 = Pin(2,Pin.OUT)
dht = DHT22(Pin(20))
slide_pot = machine.ADC(26)
i2c = I2C(0, sda=Pin(0), scl=Pin(1), freq=100000)
I2C_ADDR = i2c.scan()
lcd=LCD()
threshold_temp_rounded=0
threshold_temp=0
def LedFunc():
led0.value(1)
def display_lcd(text):
lcd.clear()
lcd.write(text)
def read_pot_value():
threshold_temp = slide_pot.read_u16() / 65535 * 100
threshold_temp_rounded = round(threshold_temp, 1) # Round to one decimal place
print("{:.1f}".format(threshold_temp_rounded)) # Format the output to one decimal place
return threshold_temp_rounded
while True:
bacabacaansuhu=read_pot_value()
dht.measure()
temp = dht.temperature()
hum = dht.humidity()
print(f"T: {temp}C H: {hum}% ")
lcd.clear()
greeting1 = 'T: ' + str(temp) + "C"
greeting2 = 'H: ' + str(hum) + "%"
greeting3 = 'Total: ' + str(bacabacaansuhu) + "C"
lcd.write(0,0,greeting1)
lcd.write(9,0,greeting2)
lcd.write(2,1,greeting3)
sleep(0.5)
if (temp > bacabacaansuhu):
led0.value(1)
else:
led0.value(0)