Help in saving value from keypad.

Good day everyone, I am trying to do a code involving a keypad, lcd and arduino uno.

The system will start with no value in array A. When we press '' it will give us chance to set a password. Below is my code when we press '' it will go to this subroutine

void change()
{
  int j=0;
  lcd.clear();
  lcd.print("Set a date : ");
  lcd.setCursor(0,1);
 
    key=kpd.getKey();
    if(key)
    {
      pass[j++]=key;
      lcd.print(key);
    }
    
  
    if(key=='#')
    {
      delay(50);
      
      for(int j=0;j<8;j++)
      {
        pass[j]=EEPROM.read(j);
        Serial.println(EEPROM.read(j));
      }
      lcd.print("  Done......");
      delay(50);
  
    }
  
 
  lcd.clear();
  lcd.print("Enter Pass2 :");
  lcd.setCursor(0,1);
  key=0;
}

The problem I get it that it skip the part where it save the password. What happened is that when '*' is pressed, it will ask to 'Set a date : ' and it directly go to 'Enter password'. It does not give me chance to key in a password to be save.

Please help me in this problem.

It does not give me chance to key in a password to be save.

It does. It's just that you are nowhere near fast enough.

You might want to look at the waitForKey() method, instead of the getKey() method in that function. And, only in that function.

PaulS:
It does. It's just that you are nowhere near fast enough.

You might want to look at the waitForKey() method, instead of the getKey() method in that function. And, only in that function.

Thanks for the reply.

What I dont understand is that I used this method in other subroutine it it works fine.Why is it work on other subroutine and doesnt work on other?. This is the code where it works :

void loop()
{
  DateTime now = rtc.now();
  //Serial.println(now.year());
  delay(10);
  key = kpd.getKey();
  if(key=='*')
  {
    change();
  }
  if (key)
  {
     password[i++]=key;
     lcd.print(key);
     //Serial.print(key);
  }
  if(key=='#')
  {
    delay(70);
    for(int j=0;j<8;j++)
    {
    pass[j]=EEPROM.read(j);
    Serial.println(EEPROM.read(j));
    }
    if(!(strncmp(password, pass,8)))
    {
      digitalWrite(ledB,HIGH);
      delay(50);
      lcd.clear();
      lcd.print("Pass Accepted");
      delay(70);
      lcd.setCursor(0,1);
      lcd.print("*.Change Pass");
      delay(70);
      lcd.clear();
      lcd.print("Enter Pass :");
      lcd.setCursor(0,1);
      i=0;
      digitalWrite(ledB,LOW);
      delay(50);
    }
      
    else
    {
      digitalWrite(ledR,HIGH);
      delay(50);
      lcd.clear();
      lcd.print("Pass Denied...");
      lcd.setCursor(0,1);
      lcd.print("*.Change Pass");
      delay(70);
      lcd.clear();
      lcd.print("Enter Pass : ");
      lcd.setCursor(0,1);
      i=0;
      digitalWrite(ledR,LOW);
      delay(50); 

      
    }
  }
}

PaulS:
You might want to look at the waitForKey() method, instead of the getKey() method in that function. And, only in that function.

I have try using the waitForKey method, and it gives the same output, the only different is that it wait for only one key to save and redirect asking 'Enter Password:'

You changed your code, and it still doesn't do what you want. Bummer. Perhaps if you posted the modified code.

You probably need to use a while loop in the function, to wait for the "I'm done entering a password" key to be pressed.