//this is rev 30 but problem with LED not remaining on during card present
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <MFRC522.h>
// OLED display configuration
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
// RFID reader configuration
#define SS_PIN 3
#define RST_PIN 2
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
// Pin configuration
const int whiteLED = 1;
const int cardAuthDelay = 2000; // 2 seconds delay after card removal
String authorisedCard = “61877DEE”; // Replace with your card ID
void setup() {
pinMode(whiteLED, OUTPUT);
digitalWrite(whiteLED, LOW);
Serial.begin(9600); // Initialize serial communications
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522
delay(100);
// Initialize OLED display with the I2C address (0x3C is common)
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}
display.display();
delay(2000);
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.print(“Scan your card”);
display.display();
}
void loop() {
// Look for new cards
if (!mfrc522.PICC_IsNewCardPresent() || !mfrc522.PICC_ReadCardSerial()) {
delay(50);
return;
}
String cardID = “”;
for (byte i = 0; i < mfrc522.uid.size; i++) {
cardID += String(mfrc522.uid.uidByte[i] < 0x10 ? "0" : "");
cardID += String(mfrc522.uid.uidByte[i], HEX);
}
cardID.toUpperCase();
Serial.println(cardID);
display.clearDisplay();
display.setCursor(0, 0);
if (cardID == authorisedCard) {
display.print("Authorised");
digitalWrite(whiteLED, HIGH);
display.display();
// Wait for the card to be removed
while (mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial()) {
delay(50);
}
// Hold the LED on for an additional 2 seconds
//delay(cardAuthDelay); // theo commented out
digitalWrite(whiteLED, LOW);
} else {
display.print("Unauthorised");
display.setCursor(0, 10);
display.print("Speak to Theo");
display.display();
delay(2000);
}
display.clearDisplay();
display.setCursor(0, 0);
display.print(“Scan your card”);
display.display();
mfrc522.PICC_HaltA();
}