print(" \nThis Program will test PIR sensor")
print(" Created by : Luqmanul Hakim")
print("\nDate : 1/4/2024")
#import libraries/modules
from machine import Pin
from utime import sleep
from machine import PWM
import oled_library
from machine import Pin, SoftI2C
from utime import sleep
#pin declaration
PIR_pin = Pin(13,Pin.IN)
Blue_LED_pin = Pin(15, Pin.OUT)
Yellow_LED_pin = Pin(2, Pin.OUT)
Buzzer_pin = PWM(4, Pin.OUT)
Oled_pin = SoftI2C(scl =Pin(22), sda=Pin(21))
#parameter declaration
#Creat an OBJECT name for module with library
#OBJECT name --> library name.class name()
screen =oled_library.SSD1306_I2C(width=128, height=64, i2c=Oled_pin)
#main program
#By default colour code is white (1)
while True:
screen.fill(1)
screen.text("SelamatHariRaya!!",0,10 ,0 )
screen.show()
while True :
Blue_LED_pin.off() #initialize
Yellow_LED_pin.off() #initialize
Buzzer_pin.init(freq= 1500, duty= 0) #initialize
motion_status = PIR_pin.value () #.value --> read digital value (1 or 0)
print ("The motion status is", motion_status)
if motion_status == True:
for i in range (5):
Blue_LED_pin.on()
Buzzer_pin.init(freq= 440, duty= 100)
sleep (0.5)
Blue_LED_pin.off()
Buzzer_pin.init(freq= 1500, duty= 0)
sleep(0.5)
Yellow_LED_pin.off()
else :
Blue_LED_pin.off()
Yellow_LED_pin.on()
sleep(1) #system delay