#from lcd_library import LCD
from lcd import LCD1602
from machine import Pin, PWM
import dht
from time import sleep
ht=dht.DHT22(Pin(16)) # Assign/define temp & humid pin number
SL_pin=Pin(26,Pin.OUT) # Assign for stroke light
Buzzer_pin=PWM(Pin(22)) # freq=5000, duty=0, resolution=13
print(Buzzer_pin)
Temp_Threshold= Humid_Threshold= 75 # for operator awareness if fan fails to run
# Initialize LCD with GPIO pins (modify for ESP32 if needed)
lcd=LCD1602(rs=4,en=5,d4=12,d5=13,d6=14,d7=15)
# to display real time temperature and humidity
last_temp=None
last_humid=None
# Function to blink the LED
def blink_SL_pin(interval=0.25):
SL_pin.on()
sleep(interval)
SL_pin.off()
sleep(interval)
while True:
ht.measure()
temp=ht.temperature()
humid=ht.humidity()
print(temp)
print(humid)
#Output the unit in "C" & "%"
print(f"Temp: {temp} °C")
print(f"Humid: {humid} %")
if temp != last_temp or humid != last_humid:
lcd.clear()
lcd.set_cursor(0,0)
lcd.putstr(f"Temp: {temp:.1f} C")
lcd.set_cursor(1,0)
lcd.putstr(f"Hum: {humid:.1f} %")
last_temp=temp
last_humid=humid
if temp >= Temp_Threshold or humid >= Humid_Threshold:
blink_SL_pin()
Buzzer_pin.freq(2000)
else:
SL_pin.off()
Buzzer_pin.freq(1)
sleep(2)