#include <Keypad.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
byte ROWS [4] = {9, 8, 7, 6};
byte COLS [4] = {5, 4, 3, 2};
int l = 0;
int nRow = 0;
char keys[4][4] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
} ;
Keypad keypad = Keypad(makeKeymap(keys), ROWS, COLS, 4,4);
LiquidCrystal_I2C lcd(0x27, 16,2);
void setup() {
lcd.init(); // initialize the lcd
// Print a message to the LCD.
lcd.backlight();
lcd.setCursor(1,0);
lcd.print("Hello Arduino!");
Serial.begin(9600);
delay(1500);
lcd.clear();
lcd.setCursor(0,0);
lcd.print(">>introductions>");
delay(1000);
lcd.setCursor(0,1);
lcd.print("*press# to clear");
delay(2500);
lcd.clear();
delay(1000);
}
void loop() {
char key = keypad.getKey();
int i = +1;
if (key != NO_KEY){
Serial.print("Entered number = ");
if (key == '#') {
Serial.print("Clear the LCD");
}
Serial.println(key);
lcd.print(key);
l+= 1;
if (l>15 and nRow==0)
{
lcd.setCursor(0, 1);
nRow=1;
}
if (l>32)
{
lcd.clear();
lcd.setCursor(0,0);
l=0;
nRow=0;
}
if (key == '#') {
lcd.clear();
}
}
}