How to tell Arduino to do nothing until there's keypad input?

Hello,

I've recently bought myself a 4x4 Matrix Membrane Keypad and try to make a user interface by simply asking their name, type it using the 4x4 Matrix Membrane Keypad, and display all of it on a 20x4 LCD I2C Module. But, different from the code that I usually use to wait until there's input to the Arduino Board on the Serial Monitor ( using while (Serial.available()==0) {} ) , I don't know the code to do that for the 4x4 Matrix Membrane Keypad and the LCD, Please help.

Thank You

Use the keypad library and do the same waiting until there is a key typed in

while(keypad.getKey() == NO_KEY); // wait until a key is pressed 

Instead of writing a line to hang the processor, start structuring your code with conditionals. The processor will skip the conditional, and be able to do other things or nothing at all, until the condition is met.

if (keypad.getKey() == '1') {
  //do something
}
//if not you wait

Ok thanks so much to both of you, really helped me a lot !

Now I face another problem, to save the answer from the user, what code do I use?
When using Serial Monitor usually I use Serial.parseInt() or Serial.readString() or Serial.parseFloat()

Here's my code:

#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4);  
//Change 0x27 to your I2C address, if it doesn't display any texts
//Change 20 to your LCD's number of columns
//Change 4 to your LCD's number of rows

#include <Keypad.h>

const byte ROWS=4;
const byte COLS=4;

char hexaKeys[ROWS][COLS]={
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'},
};

byte rowPins[ROWS]={2, 3, 4, 5};
byte colPins[COLS]={6, 7, 8, 9};

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

void setup() {
  // put your setup code here, to run once:
  lcd.init();
  lcd.backlight();

}

void loop() {
  // put your main code here, to run repeatedly:
  char myKey = myKeypad.getKey();
  
  lcd.setCursor(0,0);
  lcd.print("Input your name");

  if(myKey == '1') {
    
  }

}

Look up the examples from the library

As you can see below myKey contains the key input as an ASCII character. What exactly do you mean by by "save the answer from the user"? Is the answer a number with multiple digits? Is the answer a single digit? Do you want to save as an integer or an ASCII string? Is the input a decimal, hexadecimal, some other base representation?

Yes, How do I convert character to string?

Which one?

You add the character to a C-string (a zero-terminated character array) that you have already defined.

Example here (scroll down to password entry): How To Use A Keypad With Arduino - Makerguides.com

Hint: avoid examples that use Strings, as Strings tend to cause Arduinos to crash.

To read the answer from the user

what is this answer from the user??

You are working on an informatic project. And what is needed most in an informatic project is detailed information.

best regards Stefan

@sparxelectronics

Your other topic on the same subject deleted.

Please do not duplicate your questions as doing so wastes the time and effort of the volunteers trying to help you as they are then answering the same thing in different places.

Repeated duplicate posting could result in a temporary or permanent ban from the forum.

Could you take a few moments to Learn How To Use The Forum

It will help you get the best out of the forum in the future.

Thank you.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.