0

I'm working with a membrane keypad to make a password keypad. I have installed the Keypad and Password libraries and pieced together pieces of code with little tweaks. My question is why pressing the "#" key on the keypad prints only one message in Serial Monitor, when I have written another function that gives it another message with no errors given. I will include comments in the code, so you can get a better idea.

// Set a password.


#include <Password.h>

#include <Keypad.h>


Password myPassword = Password("1234"); // Set the Password here.

char newPassword; 

const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns

char hexaKeys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad Pin "9" is for (1-2-3-A). "8" is for (4-5-6-B). 7 = 7-8-9-C. 6 = *-0-#-D.
byte colPins[COLS] = {5, 4, 3, 2}; //connect to the column pinouts of the keypad 5 = 1-4-7-*. 4 = 2-5-8-0. 3 = 3-6-9-#. 2 = A-B-C-D.

Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); 








void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
}

void loop(){
  // put your main code here, to run repeatedly:
char customKey = customKeypad.getKey();
 if(customKey != NO_KEY){

 switch(customKey){
 case 'A': break;
 case 'B': break;
 case 'C': break; 
 case 'D': break; 
 case '#': checkPassword(); break; // Checks if the entered result matches to the password.
 case '*': changePass(); break; // Change the password.
 default: myPassword.append(customKey); // Adds a symbol.
 }
 }
}


void checkPassword(){
if(myPassword.evaluate()){
Serial.println("Access Granted"); 
}
else{
Serial.println("Access Denied");
}
delay(3000);
myPassword.reset();
Serial.println("Password reset");
}


void changePass(){
 Serial.print("Enter current password:");
 char customKey = customKeypad.getKey();
 if(customKey != NO_KEY){
  switch(customKey){
   case 'A': break;
   case 'B': break;
   case 'C': break; 
   case 'D': break; 
   case '#': IfCorrect(); break; // Check if the entered result matches the first pass, to set a new one.
   default: myPassword.append(customKey);

  }
 }
}


void IfCorrect(){  // If the entered result matches to the first password, it is supposed to let you enter a new one.
 if(myPassword.evaluate()){
 ProceedtoNewPass();

 }
}



void ProceedtoNewPass(){ // Pressing the "#" key however, (and assuming the if statement in "IfCorrect" function is true,) I don't get the following message,
 Serial.print("Enter new password"); // but the one from "void checkPassword".

}
  • another message is not one message? – Juraj Aug 31 at 16:20
  • What do you mean? – Boianskee Aug 31 at 16:22
  • explain please "the keypad prints only one message in Serial Monitor, when I have written another function that gives it another message" – Juraj Aug 31 at 16:23
  • I stated in my question, that i have written comments in my code which will give you a better idea. Please check them out. – Boianskee Aug 31 at 16:25
  • you press # it runs the changePass(), but it doesn't wait in changePass() for a key press. customKey is NO_KEY. end – Juraj Aug 31 at 16:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.