#include <SPI.h>
#include <Wire.h>
#include <MAX7219.h>
#include <DS1302.h>
#include <MFRC522.h>
#include <Spreadsheet.h>
// Define pins for MAX7219 matrix display
const int dataPin = 11;
const int clockPin = 13;
// Define pins for RTC DS1302 module
const int sdaPin = 10;
const int sclPin = 9;
// Define pins for RC522 RFID reader
const int ssPin = 8;
const int rstPin = 7;
// Define pin for buzzer
const int buzzerPin = 4;
// Create instances of MAX7219 matrix display, RTC DS1302 module, and RC522 RFID reader
MAX7219 matrixDisplay(dataPin, clockPin, 1);
DS1302 rtc(sdaPin, sclPin);
MFRC522 mfrc522(ssPin, rstPin);
// Create an instance of Spreadsheet library
Spreadsheet spreadsheet("192.168.1.100", 5000);
// Set alarm time
const byte alarmHour = 12;
const byte alarmMinute = 30;
const byte alarmSecond = 0;
void setup() {
// Initialize serial communication
Serial.begin(9600);
// Initialize MAX7219 matrix display
matrixDisplay.begin();
// Initialize RTC DS1302 module
rtc.begin();
// Set the current time
rtc.setDateTime(2023, 11, 15, 16, 58, 0);
// Set the alarm time
rtc.setAlarm1(alarmHour, alarmMinute, alarmSecond);
// Initialize RC522 RFID reader
mfrc522.PCD_Init();
}
void loop() {
// Check if the alarm is triggered and an RFID tag is present
if (rtc.checkAlarm1() && mfrc522.PICC_IsPresent()) {
// Stop the alarm
rtc.clearAlarm1();
// Turn on the buzzer
tone(buzzerPin, 1000);
// Delay for 1 second
delay(1000);
// Turn off the buzzer
noTone(buzzerPin);
// Get the card ID
MFRC522::MIFARE_Classic card = mfrc522.PICC_Read();
// Convert the card ID to a string
String cardId = "";
for (int i = 0; i < 4; i++) {
cardId += String(card.uid.byte[i]);
}
// Update the spreadsheet with the card ID and mark the attendance as "present"
spreadsheet.update(cardId, "present");
// Provide audible feedback
tone(buzzerPin, 500);
// Delay for 0.5 seconds
delay(500);
// Turn off the buzzer
noTone(buzzerPin);
// Display the card ID on the matrix display
matrixDisplay.print(cardId);
// Delay for 2 seconds before clearing the display
delay(2000);
// Clear the display
matrixDisplay.clear();
}
// Wait for the tag to be removed
while (mfrc522.PICC_IsPresent()) {
// Wait for the tag to be removed
delay(100);
}
}