#include <Keypad.h>
#include <LiquidCrystal.h>
#include <Wire.h> // libreria para bus I2C
#include <Adafruit_GFX.h> // libreria para pantallas graficas
#include <Adafruit_SSD1306.h> // libreria para controlador SSD1306
/* Fuzzer y Led */
const int ledPin = 2;
const int buzzerPin = 3;
// -------------------------------------------------------------------------------------------------
/* Display */
LiquidCrystal lcd(31, 33, 35, 37, 39, 41);
// Medidas lcd
const int anchoLcd = 16;
const int altoLcd = 2;
// Medidas lcd
const int backLightLcd = 45;
// -------------------------------------------------------------------------------------------------
/* Keypad */
const byte rowsCount = 4;
const byte columsCount = 4;
char keys[rowsCount][columsCount] = {
{ '1', '2', '3', 'A' },
{ '4', '5', '6', 'B' },
{ '7', '8', '9', 'C' },
{ '*', '0', '#', 'D' }
};
const byte rowPins[rowsCount] = { 13, 12, 11, 10 }; // Pines donde se conecta en el Arduino
const byte columnPins[columsCount] = { 9, 8, 7, 6 }; // Pines donde se conecta en el Arduino
Keypad keypad = Keypad(makeKeymap(keys), rowPins, columnPins, rowsCount, columsCount);
// -------------------------------------------------------------------------------------------------
// Variables de control
String code = ""; // Código ingresado
String activationCode = "1111"; // Código para activar la bomba
String defuseCode = "1234"; // Código para desactivar la bomba
bool bombActivated = false;
unsigned long timeLimit = 60000; // Límite de tiempo en milisegundos (1 minuto por defecto)
unsigned long startTime;
unsigned long currentTime = timeLimit;
unsigned long remainingTime;
int mistakes = 0; // Contador de errores
bool saludado = true;
// -------------------------------------------------------------------------------------------------
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buzzerPin, OUTPUT);
// Configurar el pin de la retroiluminación como salida
pinMode(backLightLcd, OUTPUT);
// Iniciar Lcd
digitalWrite(backLightLcd, HIGH); // Encender la retroiluminación
lcd.begin(anchoLcd, altoLcd); // inicializa pantalla
lcd.clear(); // Limpiar la pantalla
}
void loop() {
saludo();
if(bombActivated){
if(currentTime > 0){
armedMenu();
}
else{
digitalWrite(buzzerPin, HIGH);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("BOOOOOOOOOMMMMMM");
while(true){
int infinity = 0;
}
}
}
else{
cargarMenu();
}
char customKey = keypad.getKey();
if (customKey){
if(customKey =='#' && !bombActivated){
activateMenu();
}
}
}
void saludo() {
if (saludado) {
lcd.print("H");
delay(200);
lcd.print("o");
delay(200);
lcd.print("l");
delay(200);
lcd.print("a");
delay(200);
lcd.print(" ");
delay(300);
lcd.print("C");
delay(200);
lcd.print("r");
delay(200);
lcd.print("i");
delay(200);
lcd.print("s");
delay(200);
lcd.print("t");
delay(200);
lcd.print("i");
delay(200);
lcd.print("a");
delay(200);
lcd.print("n");
delay(500);
lcd.clear(); // Limpiar la pantalla
saludado = false;
}
}
void cargarMenu(){
lcd.setCursor(1,0);
lcd.print("Ready to Arm");
lcd.setCursor(1,1);
lcd.print("Press # to Arm");
}
void activateMenu(){
lcd.clear();
lcd.setCursor(1,0);
lcd.print("Arming code?");
lcd.setCursor(1,1);
int x=0;
while(x<4){
char customKey = keypad.getKey();
if (customKey){
lcd.print(customKey);
code += customKey;
x++;
}
}
lcd.clear();
lcd.setCursor(1,0);
if(code == activationCode){
bombActivated =true;
}
code ="";
}
void armedMenu(){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("******ARMED*****");
startTime=millis();
while(currentTime > 0){
currentTime = (timeLimit-(millis()-startTime));
lcd.setCursor(1,1);
lcd.print(int(currentTime/1000));
lcd.print(":");
lcd.print(int(currentTime % 10));
/*delay(500);
digitalWrite(ledPin, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
*/
}
}