print("Hello, SMART DOOR DETECTION")
print('PRACTICAL TEST')
print('4/12/2023')
print('PUTERA AFIQ')

#import all libraries
import oled_library
from machine import Pin, SoftI2C
from utime import sleep 

#pin declaration
pin_oled = SoftI2C(scl=Pin(33), sda=Pin(25))
pir = Pin(27, Pin.IN)
red_alarm = Pin(19, Pin.OUT)

#declare object name
skrin = oled_library.SSD1306_I2C(width=126, height=64, i2c=pin_oled)

#main program
while True:
  motion = pir.value()
  if motion == 1: 
    
    for u in range (5):
      skrin.fill(1)
      skrin.text('HI MY OWNER', 18, 10, 0)
      skrin.text('WELCOME BACK', 14, 25, 0)
      skrin.text('HAVE A GOOD REST', 0, 40, 0)
      skrin.show()
      red_alarm.on()
      sleep(0.5)
      red_alarm.off()
      sleep(0.5)
  else:
    skrin.fill(0)
    skrin.show()
  
  sleep(2)