#include <LiquidCrystal.h>
// Initialize the LCD with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// Define the pin numbers
const int ledPin = 13;
const int buttonPin = 7;
// Variables to store attempts and unauthorized access status
int attempts = 0;
String correctCode = "2347248";
String name = "Rajendran M S";
bool unauthorizedAccess = false;
void setup() {
// Set the pin modes
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);
// Initialize the LCD and print the initial pattern
lcd.begin(16, 2);
displayPattern();
}
void loop() {
// Check if the button is pressed
if (digitalRead(buttonPin) == LOW) { // Button is pressed when the state is LOW
delay(50); // Debounce delay
if (digitalRead(buttonPin) == HIGH) { // Confirm the button is still pressed
attempts++;
while(digitalRead(buttonPin) == LOW); // Wait until the button is released
}
}
Serial.println(attempts);
// Check if the maximum number of attempts is reached
if (attempts >= 3 && !unauthorizedAccess) {
unauthorizedAccess = true;
blinkLED();
}
}
void displayPattern() {
lcd.setCursor(0, 0);
lcd.print("R.M.S. 7248");
lcd.setCursor(0, 1);
lcd.print(createUniqueSequence(name, correctCode));
}
String createUniqueSequence(String name, String code) {
String sequence = "";
int minLength = min(name.length(), code.length());
for (int i = 0; i < minLength; i++) {
sequence += String((int)name[i], HEX) + " ";
sequence += String(code[i]) + " ";
}
return sequence;
}
void blinkLED() {
for(int i = 0; i < 10; i++) { // Blink LED 10 times to indicate unauthorized access
digitalWrite(ledPin, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
delay(500);
}
}