analog kepad config and LCD I2C code development

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;
}
 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);
    }}

Since targetkey never changes inside this while loop once you're in it you're stuck there forever. You should read a new key once you've added this one to your array and printed it.

I understand you now for looping issue.

even if I deleted the curly bracket and added it to the rest code of the loop.

the same issue is that I get stuck it never reads the targetkey !!

now I'm working on the code ....

well, I got into the .cpp and .h files for the analog keypad project I got from the web. And I thought to modify the files which they basically works fine,

I'm thinking to modify it .. and see what results I should get.

like this piece of code I found in the .cpp file

#include "AnalogVoltageRead.h"
AnalogVoltageRead::AnalogVoltageRead(byte ap){
	analogPin = ap;
	debounceTime = 200;
	threshold = 5;
}

void AnalogVoltageRead::setDebounceTime(unsigned int time){
	debounceTime = time;
}

void AnalogVoltageRead::setThresholdValue(byte tv){
	threshold = tv;

what does :: means?

is it necessary? can I delete them and include my own variables?

:: is the scope operator. It means that the function or variable after it is referring to the one in the class before it. So AnalogVoltageRead::setDebounceTime(time) refers to the setDebounceTime function in the AnalogVoltaeRead class and not some other function by the same name that may exist elsewhere.

A tutorial on C++ classes may help clear some of that up.