Untitled

 avatar
unknown
plain_text
2 years ago
1.8 kB
2
Indexable
#include <Keypad.h>
#include "modules/SecurityKey.cpp"

SecurityKey sec;

int RED = 12;
int GREEN = 13;
int BUZZER = 9; // Buzzer pin

int resetDelay = 10000; //Delay before the Lock resets from open
unsigned long prevTime;

bool passCorrect = false;
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'o','0','c'}
};
byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {8, 7, 6}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup(){
Serial.begin(9600);
sec.setPassKey("0000");//Set the Desired secret key;
pinMode(GREEN, OUTPUT);
pinMode(RED, OUTPUT);
pinMode(BUZZER, OUTPUT);

}

void loop(){
char key = keypad.getKey();

if (key != NO_KEY){
// Serial.println(key);
if(String(key) == "o"){
//if okay is pressed, do something
passCorrect = sec.validateKeys();
if(passCorrect){
prevTime = millis();
digitalWrite(BUZZER, HIGH); // Buzz to indicate correct password
} else {
digitalWrite(BUZZER, LOW); // Turn off buzzer for incorrect password
}
sec.clearInput();
}else if(String(key) == "c"){
//clearInput if c(clear) is detected
sec.clearInput();
digitalWrite(BUZZER, LOW); // Turn off buzzer on clear
Serial.println("Input cleared off");

}else{
  sec.inputKeys(key);

} 
Serial.println(String(key));

}

//Toggle LED and buzzer states
if(passCorrect){
digitalWrite(GREEN, HIGH);
digitalWrite(RED, LOW);

if(millis() - prevTime >= resetDelay && passCorrect == true){   
  passCorrect = false;        
}      

}else{
digitalWrite(RED, HIGH);
digitalWrite(GREEN, LOW);
digitalWrite(BUZZER, LOW); // Turn off buzzer for incorrect password
}

}