#include <Keypad.h>
#include <LiquidCrystal_I2C.h>
char keys[4][4] = {
{ '1', '2', '3', 'A' },
{ '4', '5', '6', 'B' },
{ '7', '8', '9', 'C' },
{ '*', '0', '#', 'D' }
};
uint8_t colPins[4] = {23, 25, 27, 29};
uint8_t rowPins[4] = {33, 35, 37, 39};
String type = "Typed: ";
String view = "";
int asterisk_press = 0;
Keypad keypad = Keypad(makeKeymap(keys), colPins, rowPins, 4, 4);
LiquidCrystal_I2C lcd(0x27, 20, 4);
void setup() {
lcd.begin(20, 4);
lcd.setCursor(0, 0);
lcd.print(type);
}
void loop() {
char key = keypad.getKey();
if (key == '#') {
view = "";
lcd.clear();
} else if (key == '*') {
asterisk_press++;
if (asterisk_press % 2) {
type = "Pressed: ";
} else {
type = "Typed: ";
}
lcd.clear();
} else if (key != NO_KEY) {
view += key;
lcd.clear();
}
lcd.setCursor(0, 0);
lcd.print(type + view);
}