Hello,
I'm working on this project for quite a time.
I finished the hardware configuration and working on the code development.
I know how to display messages and perform other simple actions.
The issue I have now is that I want to enter password, and then if the password is correct then you continue. Otherwise, it display wrong password.
This is the code.
#include <Keypad.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include <AnalogVoltageRead.h>
#define analogPin A0
AnalogVoltageRead AVRD(analogPin);
LiquidCrystal_I2C lcd(0x27,2, 1, 0, 4, 5, 6, 7);
char Password_Array[4];
char Master[]= "123";
byte data = 0;
char targetkey;
byte ok = 13;
byte no = 12;
void setup(){
Serial.begin(9600);
lcd.begin(16,2);
lcd.setBacklightPin(3,POSITIVE);
lcd.setBacklight(HIGH);
pinMode(ok,OUTPUT);
pinMode(no,OUTPUT);
}
void loop(){
lcd.setCursor(2,0);
lcd.print("** Welcome **");
delay(1000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Enter Password");
targetkey = AVRD.readKey();
while(targetkey){
//if(targetkey != KEY_NOT_PRESSED)
if(targetkey){
Password_Array[data] = targetkey;
lcd.setCursor(data,1);
lcd.print(Password_Array[data]);
data++;
Serial.println(targetkey);
}}
// !Key NO_KEY}
if(data==3)
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Password is ");
if(!strcmp(Password_Array, Master)){
lcd.print("Good");
digitalWrite(ok,HIGH);
delay(1000);
lcd.clear();
cleardata();}
else{
lcd.print("Bad");
digitalWrite(no,HIGH);
delay(1000);
lcd.clear();
cleardata();
}}}
void cleardata()
{
while(data!=0)
{ // This can be used for any array size,
Password_Array[data--] = 0; //clear array for new data
digitalWrite(ok,LOW);
digitalWrite(no,LOW);
}
//return;
}