from machine import Pin, ADC
from esp32_gpio_lcd import GpioLcd
import time
# Setup LCD
lcd = GpioLcd(
rs_pin=Pin(14),
enable_pin=Pin(27),
d4_pin=Pin(26),
d5_pin=Pin(25),
d6_pin=Pin(33),
d7_pin=Pin(32),
num_lines=2,
num_columns=16
)
# Setup Sensor
ldr = ADC(Pin(35))
temp = ADC(Pin(34))
ldr.atten(ADC.ATTN_11DB)
temp.atten(ADC.ATTN_11DB)
while True:
ldr_value = ldr.read()
temp_value = temp.read()
lux = (1 - (ldr_value / 4095)) * 1000
suhu = (1 - (temp_value / 4095)) * 80 # max 80
# =========================
# LOGIKA KONDISI (pakai AND semua)
# =========================
if lux > 600 and suhu > 60:
status = "Kebakaran"
elif lux > 200 and suhu > 40:
status = "Waspada"
else:
status = "Aman"
lcd.clear()
# Baris pertama: tampilkan Lux dan Suhu
lcd.move_to(0, 0)
lcd.putstr("L:{:.0f} S:{:.0f}".format(lux, suhu))
# Baris kedua: tampilkan status
lcd.move_to(0, 1)
lcd.putstr(status)
time.sleep(1)