Hello all,
I am having a code for password operated digital lock with 4x4 keypad.
I modified it as per my application to make an output LED High for single digit password say "1"
in a desired amount of time for On and OFF state
Now i want to enter another password with 2 digit say "11" to glow the LED for a different ON & OFF time (other than previous case).
The 2 password entry options should be on the same program & same keyboard but individually working and not interfering each other
Please check the code as only the single digit "1" is working but not allowing "11" to get on work.
So how to solve it ?
#include <LCD_I2C.h>
// Include Keypad library
#include <Keypad.h>
#include <SoftwareSerial.h>
#include "DFRobotDFPlayerMini.h"
//const int pin1 = LOW;
//int pin1State=0;
//bool pinState = LOW;
#define Num_Length 2
#define Num_Length1 3
int signalPin = 12;
char Data[Num_Length];
char Master[Num_Length] = "1";
char Data1[Num_Length1];
char Master1[Num_Length1] = "11";
char customKey;
byte data_count = 0, master_count = 0;
byte data_count1 = 0, master_count1 = 0;
// Constants for row and column sizes
const byte ROWS = 4;
const byte COLS = 4;
// Array to represent keys on keypad
char hexaKeys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
// Connections to Arduino
byte rowPins[ROWS] = {9, 8, 7, 6};
byte colPins[COLS] = {5, 4, 3, 2};
// Create keypad object
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
// Create LCD object
LCD_I2C lcd(0x27, 16, 2);
SoftwareSerial mySoftwareSerial(10, 11); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
byte pbRegister = 0;
void setup(){
Serial.begin(9600);
mySoftwareSerial.begin(9600);
if (!myDFPlayer.begin(mySoftwareSerial)) { //Use softwareSerial to communicate with mp3.
while(true){
delay(0); // Code to compatible with ESP8266 watch dog.
}
}
myDFPlayer.volume(29);
myDFPlayer.playFolder(2, 2);
lcd.begin();
lcd.backlight();
pinMode(signalPin, OUTPUT);
}
void loop(){
// Get key value if pressed
char customKey = customKeypad.getKey();
if (customKey)
{
Data[data_count] = customKey;
lcd.setCursor(data_count,1);
lcd.print(Data[data_count]);
data_count++;
}
if(data_count == Num_Length-1)
{
lcd.clear();
//clearData();
switch(data_count)
{
case 1:
if(!strcmp(Data, Master)){
lcd.print("Correct");
digitalWrite(signalPin, HIGH);
delay(1000);
}
else{
lcd.setCursor(0,0);
lcd.print("incorrect");
lcd.setCursor(0,1);
lcd.print("InValid Entry");
delay(2000);
}
clearData();
break;
} //switch end
//lcd.clear();
} //if(data_count == Num_Length-1)
pbRegister = 0;
delay(100);
if (customKey)
{
Data1[data_count1] = customKey;
lcd.setCursor(data_count1,1);
lcd.print(Data1[data_count1]);
data_count1++;
}
if(data_count1 == Num_Length1-1)
{
lcd.clear();
//clearData();
switch(data_count1)
{
case 2:
if(!strcmp(Data1, Master1)){
lcd.setCursor(3,0);
lcd.print("all good");
lcd.setCursor(3,1);
lcd.print("opened");
digitalWrite(signalPin, HIGH);
delay(5000);
}
else{
lcd.setCursor(0,0);
lcd.print("go back");
lcd.setCursor(0,1);
lcd.print("InValid Entry");
delay(7000);
}
clearData();
break;
} //switch end
//lcd.clear();
} //if(data_count == Num_Length-1)
} // void loop()
void clearData()
{
while(data_count !=0)
{
Data[data_count--] = 0;
}
while(data_count1 !=0)
{
Data1[data_count1--] = 0;
}
return;
}
Please help me out !! Thanksssss . . .