import machine
import time
import Alarm
import ssd1306
from machine import Timer
secret_code = [1,1,5,5]
entered_code = []
alarm_on = False
horizontal = [22, 21, 19, 18]
vertical = [5, 4, 2, 15]
symbols = ["1", "2", "3", "A", "4", "5", "6", "B", "7", "8", "9", "C", "*", "0", "#", "D"]
keypad = Alarm.Keypad(horizontal, vertical, symbols)
pir_sensor = machine.Pin(12, machine.Pin.IN)
reed_contact = machine.Pin(14, machine.Pin.IN, machine.Pin.PULL_UP)
panic_button = machine.Pin(27, machine.Pin.IN, machine.Pin.PULL_UP)
buzzer = machine.Pin(25, machine.Pin.OUT)
relais = machine.Pin(26,machine.Pin.OUT)
#oled
sda=machine.Pin(32)
scl=machine.Pin(33)
i2c=machine.I2C(0,sda=sda, scl=scl, freq=400000)
oled = ssd1306.SSD1306_I2C(128, 64, i2c)
message = ""
status_led = machine.Pin(13, machine.Pin.OUT)
alarm_led = machine.Pin(23, machine.Pin.OUT)
alarm = Alarm.Alarm(keypad, status_led, reed_contact, pir_sensor, panic_button, alarm_led, oled)
while True:
#1111* to arm alarm
#1111# to set stay mode
alarm.check_buttons_pressed()
alarm.check_alarm_state()
# relais.value(1)
# buzzer.value(not buzzer.value())
# if message != "Hello World!":
# message = "Hello World!"
# oled.fill(0)
# oled.text("Hello World!", 0, 0)
# oled.show()
# timers!!!
# import machine
# import time
# from machine import Timer
# led = machine.Pin(13, machine.Pin.OUT)
# led1 = machine.Pin(33, machine.Pin.OUT)
# print(time.ticks_ms()//100)
# def mycallback(tim):
# led.value(not led.value())
# print(time.ticks_ms()//100)
# def mycallback1(tim1):
# led1.value(not led1.value())
# print(time.ticks_ms()//100)
# tim = Timer(-1)
# tim.init(period=500, mode=Timer.PERIODIC, callback=mycallback)
# tim1 = Timer(-2)
# tim1 .init(period=1000, mode=Timer.PERIODIC, callback=mycallback1)