print("SMART CLASSROOM SYSTEM")
print("BY: DANIAL HAFIZ")
print("DATE: 2/5/2024")
#Import Library
import oled_library
from machine import Pin, SoftI2C, PWM
from utime import sleep
#Pin Declaration
PIR_sensor = Pin(12, Pin.IN)
Green_led = Pin(4, Pin.OUT)
Red_led = Pin(2, Pin.OUT)
oled_pin = SoftI2C(scl=Pin(22), sda=Pin(21))
push_button = Pin(13, Pin.IN)
Buzzer = PWM(Pin(18, Pin.OUT))
#Parameter Declaration
Number_of_people = 0
Absent_student = 0
Total_student = 10
#Main Program
while True:
motion_status = PIR_sensor.value()
Green_led.off()
Red_led.off()
display = oled_library.SSD1306_I2C(width=128, height=64, i2c=oled_pin, external_vcc=False)
logic_state = push_button.value()
Buzzer.init(freq=1, duty=0)
if motion_status == True:
Green_led.on()
Red_led.off()
Number_of_people = Number_of_people + 1
print("NUMBER OF STUDENT ATTEND THIS CLASS = ", Number_of_people)
print("TOTAL OF STUDENT FOR THIS CLASS = ", Total_student)
display.fill(0)
display.text("SELAMAT DATANG", x=5, y=10, col=1)
display.text("KE KELAS", x=5, y=20, col=1)
display.show()
elif logic_state == True:
for m in range(10):
Buzzer.init(freq=800, duty=100)
sleep(0.5)
Buzzer.init(freq=1047, duty=0)
sleep(0.5)
display.fill(0)
display.text("CLASS DISMISS", x=5, y=10, col=1)
display.show()
sleep(2)
print("NUMBER OF STUDENT ATTEND THIS CLASS = ", Number_of_people)
print("TOTAL OF STUDENT FOR THIS CLASS = ", Total_student)
else:
Number_of_people = Number_of_people + 0
Absent_student = Total_student - Number_of_people
Red_led.on()
Green_led.off()
print("NUMBER OF STUDENT ATTEND THIS CLASS = ", Number_of_people)
print("NUMBER OF ABSENT STUDENT = ", Absent_student)
motion_status = 0
sleep(5)Loading
esp32-devkit-v1
esp32-devkit-v1