#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
LiquidCrystal_I2C lcd(0x27,16,2);
const byte rows = 4;
const byte cols = 4;
char key[rows][cols] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[rows] = {9, 8, 7, 6};
byte colPins[cols] = {5, 4, 3, 2};
Keypad keypad = Keypad(makeKeymap(key), rowPins, colPins, rows, cols);
int x=0;
int y=0;
void setup() {
Serial.begin(9600);
Serial.println(x);
lcd.init();
lcd.clear();
lcd.backlight(); // Make sure backlight is on
// Print a message on both lines of the LCD.
}
void loop() {
char keyPressed = keypad.getKey();
if (keyPressed >0 && keyPressed != 'D') {
lcd.setCursor(x,y);
lcd.print(keyPressed);
x=x+1;
Serial.println(x);
}
if (keyPressed=='D'){
x=x-1;
lcd.setCursor(x,y);
lcd.print(" ");
Serial.println(x);
}
}