import machine
from time import sleep, ticks_ms
from keypad import keyboardcheck
from extra import revbool
from sh1106 import SH1106_I2C
import ledstrip
pir = machine.Pin(26, machine.Pin.IN, machine.Pin.PULL_DOWN)
pirled = machine.Pin (13,machine.Pin.OUT)
panic = machine.Pin(25, machine.Pin.IN, machine.Pin.PULL_UP)
buzzer = machine.Pin(14,machine.Pin.OUT)
pirtoestand = 0
pirled.value(0)
sda= machine.Pin(21)
scl= machine.Pin(22)
i2c= machine.I2C(0,sda=sda, scl=scl, freq=400000)
alarmaan = False
ledstrip.leds(alarmaan)
dispstat = "Alarm uit"
indringer = False
oled = SH1106_I2C(128,64,i2c)
oled.fill(0)
oled.text("Systeem gestart",0,0)
oled.text(dispstat,0,10)
oled.show()
while True:
pirtoestand = pir.value()
pirled.value(pirtoestand)
if pirtoestand==1 and alarmaan == True:
indringer = True
print ("help er is een indringer")
buzzer(1)
else:
buzzer(0)
panictoestand = panic.value()
if panictoestand == 0:
print("Paniek")
buzzer(1)
else:
buzzer(0)
ok = keyboardcheck()
if ok == True:
alarmaan = revbool(alarmaan)
if alarmaan == True:
dispstat = "Alarm aan"
else:
dispstat = "Alarm uit"
oled = SH1106_I2C(128, 64, i2c)
oled.fill(0)
oled.text(dispstat, 0, 0)
oled.show()
ledstrip.leds(alarmaan)