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.
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
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()
#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') {
}
}
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?
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.