// Matthias Jiménez Villamar
// Security Pass Anti-threat (SPAT)
// 15/07/2025
//MJ
#include <Keypad.h>
#include <LiquidCrystal.h>
String pass = "123ABC", enteredPass="";
int intentosFallidos = 0, intentosTotales = 0;
unsigned long startTime;
const int TIME_LIMIT = 10000;
const int pinRed = 35, pinGreen = 37, pinBlue = 39;
const byte rows = 4, cols = 4;
byte RowsPin[] = {9, 8, 7, 6};
byte ColsPin[] = {5, 4, 3, 2};
char keys[4][4] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
Keypad keyPad=Keypad(makeKeymap(keys), RowsPin, ColsPin, rows, cols);
LiquidCrystal screen(13, 12, 22, 24, 26, 28);
void setup() {
pinMode(pinRed, OUTPUT);
pinMode(pinGreen, OUTPUT);
pinMode(pinBlue, OUTPUT);
Serial.begin(9600);
screen.begin(20, 4);
screen.setCursor(2, 1);screen.print("PROFESSIONAL SPAT");
screen.setCursor(5, 2);screen.print("ENTERPRISE");
delay(800);
screen.clear();
startTime=millis();
}
void loop(){
mostrarTiempoRestante();
screen.setCursor(0, 0);screen.print("Enter Key: ");
char pressKey = keyPad.getKey();
if (pressKey){
enteredPass += pressKey;
screen.setCursor(enteredPass.length() - 1, 1);
screen.print("*");
if (enteredPass.length() == pass.length()) {
checkPass();
}
}
if((millis()-startTime)>=TIME_LIMIT) {
bloquearSistema();
}
}
void checkPass() {
screen.clear();
if (enteredPass == pass) {
screen.setCursor(6, 1);
screen.print("CORRECT!!");
colors(0, 0, 255);
delay(800);
colors(0, 0, 0);
intentosFallidos=0;
Serial.print(++intentosTotales);
Serial.print(": TRUE: ");
Serial.println(enteredPass);
} else {
screen.setCursor(5, 1);
screen.print("INCORRECT!!");
colors(0, 0, 255);
delay(800);
colors(0, 0, 0);
intentosFallidos++;
Serial.print(++intentosTotales);
Serial.print(": FALSE: ");
Serial.println(enteredPass);
if(intentosFallidos==3){bloquearSistema();}
}
enteredPass="";
screen.clear();
startTime=millis();
}
void mostrarTiempoRestante() {
unsigned long elapsed=millis()-startTime;
unsigned long remaining=(TIME_LIMIT - elapsed);
screen.setCursor(0, 3);
screen.print("Time --> ");
screen.print(remaining / 1000);
screen.print("s. ");
screen.print(remaining % 1000);
screen.print("ms. ");
}
void bloquearSistema() {
screen.clear();
Serial.println("\n===== System Blocked =====");
Serial.println("A Safety Method By Matthias Jiménez V. \n");
Serial.println("This block, could has started by four causes:");
Serial.println(" - The waiting time has ended.");
Serial.println(" - You've entered the wrong key 3 TIMES.");
Serial.println(" - You're Stupid");
Serial.println(" - You don't have any idea about the password.");
screen.setCursor(3, 0);screen.print("System Blocked");
screen.setCursor(0, 2);screen.print("Generating Code ...");
screen.setCursor(18, 3);screen.print("MJ");
colors(255, 0, 0);
delay(1000);
screen.setCursor(0, 2);screen.print("Code: 500xKey ");
while(true){
colors(255, 0, 0);
delay(500);
colors(0, 0, 0);
delay(500);
}
}
void colors(int red, int green, int blue){
analogWrite(pinRed, red);
analogWrite(pinGreen, green);
analogWrite(pinBlue, blue);
}