Arduino keypad: wait for key press

Hello friends, tho its late still greeting for new year!!!

Currently I am working on a project which is basically a customer feedback machine which is to be installed at gas station.

The idea behind this project is to have customer feedback for the services they use at this particular gas station.

for this project I am using Mega2560 obviously bcoz of its vast GPIOs. I am using 20X4 LCd as a output device and 4X4 matrix keypad to enable the user to choose for which service he/she wishes to register the feedback for, also there are 15 buttons which will be read as a user input for the entered feedback(for the 3 types of services each having 5 buttons to registered the feedback).

what I have in my mind is;

  1. On initialization of the system, it asks the user if he wants to enter his cell phone number (A → yes and B → No)

  2. If the user chooses to enter his cell phone number by pressing the A, the system should take users mobile number and store it. And then, ask for which service the user wishes to give feedback for

  3. If not, system directly asks for which service the user wish to register his feedback.

  4. for getting the feedback for the service, the user is asked to press (A → Air, B-> Washroom, C-> overall service)

  5. after the user makes his choice of entering the feedback the user presses anyone among the 15 buttons to register his particular feedback.

  6. after entering the feedback the system acknowledges the user about successful registration of his feedback and returns back to initial stage to have another feedback

My problem is that, after pressing key A the system doesn’t wait for the user to enter his cell phone number and rushes back to initial stage. So is there any way to do so? I have posted the code which I have built uptil now.

#include <LiquidCrystal.h>  
LiquidCrystal lcd(53,10,11,12,13,38);

#include <Keypad.h>

const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
byte rowPins[ROWS] = {5, 2, 3, 4}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {39, 40, 41,42}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

char keycount=0;
char code[11]; //Hold pressed keys

void setup(){
  Serial.begin(9600);
 lcd.begin(20,4);
 lcd.print("hello");
 delay(1000); 
 lcd.clear();

}
  
void loop()
{
// On intialisation  
  lcd.print("Do you want to");
  lcd.setCursor(0,1);
  lcd.print("register your");
  lcd.setCursor(0,2);
  lcd.print("Mobile number?");
  lcd.setCursor(0,4);
  lcd.print("Yes -> A     No -> B");

  char key = keypad.getKey();
  if(key)
  {
    lcd.clear();
    if(key == 'A')
    {
      lcd.clear();
      lcd.print("Mobile Number Plz");
     char key = keypad.getKey();
     if(key)
    {
     lcd.clear();
     if (key && (keycount<=10) && (key !='=') && (key !='C'))
    {      
      lcd.print(key); //To display entered keys
      code[keycount]= key;
      keycount++;
    }
    }
  }
}

Waiting for valuable help. Thanks in advance

also there are 15 buttons which will be read as a user input for the entered feedback(for the 3 types of services each having 5 buttons to registered the feedback).

You could do that with 5 switches. The meaning of the switch inputs, regardless of how many there are, only has meaning when what to provide feedback for is known.

So is there any way to do so?

Look at all the methods available in the keypad class. waitForkey() is one of them.

PaulS:
You could do that with 5 switches. The meaning of the switch inputs, regardless of how many there are, only has meaning when what to provide feedback for is known.

thats not m worried about right now I can deal with it later.

PaulS:
Look at all the methods available in the keypad class. waitForkey() is one of them.

can U guide me with any link or anything where I can look for it?

By the way, you have two variables named key. That is NOT a good idea. You have no way to handle the user making a mistake in entering his/her phone number. You REALLY should have. Both backspace, to correct entering one wrong digit, noticed right away, and clear, to start over, should be supported.

Clearing the LCD after each digit is entered doesn't seem like a reasonable thing to do.

can U guide me with any link or anything where I can look for it?

A library, in Arduino terms, is nothing more than a header file (or more than one) and a source file (or more than one). You can use any text editor to examine any header file to see what the library can do, and to examine any source file, to see how it does it.

PaulS:
By the way, you have two variables named key. That is NOT a good idea. You have no way to handle the user making a mistake in entering his/her phone number. You REALLY should have. Both backspace, to correct entering one wrong digit, noticed right away, and clear, to start over, should be supported.

Clearing the LCD after each digit is entered doesn't seem like a reasonable thing to do.

thanks for the suggestions and improvisations will surely include those features.

@PaulS please direct me to the link where I can see any examples related to my problem. that would be really greatful of u...