from machine import Pin, I2C
import ssd1306
import time
# I2C setup for OLED
i2c = I2C(0, scl=Pin(22), sda=Pin(21))
oled = ssd1306.SSD1306_I2C(128, 64, i2c)
# Student buttons (active LOW)
buttons = [
Pin(12, Pin.IN, Pin.PULL_UP),
Pin(13, Pin.IN, Pin.PULL_UP),
Pin(14, Pin.IN, Pin.PULL_UP),
Pin(25, Pin.IN, Pin.PULL_UP),
Pin(26, Pin.IN, Pin.PULL_UP)
]
# LEDs for students
leds = [
Pin(2, Pin.OUT),
Pin(4, Pin.OUT),
Pin(5, Pin.OUT),
Pin(18, Pin.OUT),
Pin(19, Pin.OUT)
]
# Buzzer
buzzer = Pin(15, Pin.OUT)
# Reset button
reset_button = Pin(27, Pin.IN, Pin.PULL_UP)
# Student data
student_names = ["Ali", "Siti", "Ahmad", "Zara", "Daniel"]
attendance = [0, 0, 0, 0, 0]
def reset_attendance():
global attendance
attendance = [0, 0, 0, 0, 0]
for led in leds:
led.value(0)
oled.fill(0)
oled.text("Attendance Reset!", 0, 0)
oled.show()
print("Attendance list cleared.")
time.sleep(1)
# Initialize
reset_attendance()
while True:
# Reset check
if reset_button.value() == 0:
reset_attendance()
time.sleep(0.5)
continue
# Check student buttons
for i, btn in enumerate(buttons):
if btn.value() == 0 and attendance[i] == 0:
attendance[i] = 1
leds[i].value(1)
buzzer.value(1)
oled.fill(0)
oled.text("Student Present:", 0, 0)
oled.text(student_names[i], 0, 20)
oled.show()
print(f"{student_names[i]} marked present!")
time.sleep(0.3)
buzzer.value(0)
time.sleep(0.1)