hello guys.
i am trying to write code where
if i press "1" in 4x4 matrix keypad it will show "ok" in lcd .
or
if i press "2" in 4x4 matrix keypad it will show "no" in lcd .
what will be the code for it ? i am new in arduino programming.
m using if else statement but it doesnt working when i m pressing keypad .
m trying like this-
void loop
{
if (key==1) {
Serial.println("hello world");
}
if (key==2) {
Serial.println("hello there");
}
else {
Serial.println("press anything");
}
}
just want to know how can i do this .
thats my full code -
#include <Keypad.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(5, 4, 3, 2, A4, A5);
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] = {A0, A1, 11, 10}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {9, 8, 7, 6}; //connect to the column pinouts of the keypad
int LCDCol = 0;
int LCDRow = 0;
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){
Serial.begin(9600);
lcd.begin(16, 2);
lcd.setCursor(LCDCol, LCDRow);
}
void loop(){
char key = keypad.getKey();
if (key==1) {
lcd.print("hello world");
}
if (key==2) {
lcd.print("hello there");
}
else {
.println("press anything");
}
delay(10);
// Delay a little bit to improve simulation performance
}