from machine import ADC, Pin, I2C
from time import sleep
from lcd_api import LcdApi
from i2c_lcd import I2cLcd
smoke_sensor = ADC(26)
buzzer = Pin(15, Pin.OUT)
led = Pin(14, Pin.OUT)
I2C_ADDR = 0x27
i2c = I2C(0, sda=Pin(0), scl=Pin(1), freq=400000)
lcd = I2cLcd(i2c, I2C_ADDR, 2, 16)
THRESHOLD = 40000
lcd.putstr("Rauchmelder Startet")
sleep(2)
lcd.clear()
while True:
value = smoke_sensor.read_u16()
print("Rauchwert:", value)
#lcd.clear()
lcd.move_to(0, 0)
lcd.putstr("Rauch: {}".format(value))
if value > THRESHOLD:
buzzer.on()
led.on()
lcd.move_to(0, 1)
lcd.putstr("!! ALARM !!")
print("Rauch erkannt!")
else:
buzzer.off()
led.off()
lcd.move_to(0, 1)
lcd.putstr("Alles OK")
sleep(1)