Hi guys..
I am building a keypad which will be used to open an automatic gate.
It uses a serial LCD from seeedstudios.com, an arduino pro mini, and a keypad.
My problems arise in the code. I've hit a block I just don't know what to do at this point. I want to be able to change the password while the program is running. I don't want to have to remove it from the gate and reprogram it every time I need to change the password. But I'm really not sure what to do! I'm no expert at programming. It's a bit of a mess. I'd really, REALLY appreciate any help guys. Thanks again in advance.
#include <Password.h>
#include <Keypad.h>
#include <SerialLCD.h>
#include <NewSoftSerial.h>
Password password = Password( "0000" );
SerialLCD slcd(12,13);
int count = 0;
int buzzer = 10;
int relay = 11;
int talkRelay = 9;
const byte ROWS = 4; // Four rows
const byte COLS = 3; // columns
// Define the Keymap
char keys[ROWS][COLS] = {
{
'1','2','3' }
,
{
'4','5','6' }
,
{
'7','8','9' }
,
{
'*','0','#' }
};
byte rowPins[ROWS] = {
5, 4, 3, 2 };// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
byte colPins[COLS] = {
8, 7, 6 };
// Create the Keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){
slcd.begin();
slcd.clear();
slcd.backlight();
slcd.setCursor(0,1);
slcd.print(" ENTER PASSWORD ");
pinMode(buzzer, OUTPUT);
pinMode(relay, OUTPUT);
pinMode(talkRelay, OUTPUT);
keypad.addEventListener(keypadEvent);
}
void loop(){
keypad.getKey();
}
void keypadEvent(KeypadEvent eKey){
switch (keypad.getState()){
case PRESSED:
if(eKey != '4')
digitalWrite(buzzer, HIGH);
delay(50);
digitalWrite(buzzer, LOW);
if(eKey != '*' || '#')
password.append(eKey);
if(count == 3){
slcd.setCursor(0,0);
slcd.print(" ENTER NEW PWORD");
password.reset();
}
switch (eKey){
case '#':
count++;
if(count == 1){
slcd.setCursor(0,0);
slcd.print("change password?");
slcd.setCursor(0,1);
slcd.print(" # to continue ");
}
if(count == 2){
slcd.setCursor(0,0);
slcd.print(" ENTER OLD PWORD");
}
case '*':
if(count == 3){
password.set(password.append(eKey));
count = 0;
}
}
void checkPassword(){
if(count == 2){
if(password.evaluate()){
count == 3);
}
if (password.evaluate()){
slcd.clear();
slcd.setCursor(2,0);
slcd.print("Welcome Home");
digitalWrite(13, HIGH);
digitalWrite(buzzer, HIGH);
digitalWrite(relay, HIGH);
delay(400);
digitalWrite(buzzer, LOW);
digitalWrite(relay, LOW);
password.reset();
delay(4000);
slcd.clear();
slcd.setCursor(0,0);
slcd.print("HIT * TO CALL OR");
slcd.setCursor(0,1);
slcd.print(" ENTER PASSWORD ");
//Add code to run if it works
}
else{
slcd.clear();
slcd.setCursor(0,0);
slcd.print(" Wrong Password ");
slcd.setCursor(0,1);
slcd.print(" Piss Off! ");
digitalWrite(buzzer, HIGH);
delay(100);
digitalWrite(buzzer, LOW);
delay(100);
digitalWrite(buzzer, HIGH);
delay(100);
digitalWrite(buzzer, LOW);
delay(100);
digitalWrite(buzzer, HIGH);
delay(100);
digitalWrite(buzzer, LOW);
digitalWrite(13, LOW);
delay(2000);
slcd.clear();
slcd.setCursor(0,1);
slcd.print(" ENTER PASSWORD ");
password.reset();
//add code to run if it did not work
}
}