#include <I2CKeyPad.h>
#include <LiquidCrystal_I2C.h>
#define deltaTime(val) (millis() - val)
I2CKeyPad keyPad(0x21);
char keypad_layout[19] = "123A456B789C*0#DNF"; // N = NO_KEY, F = FAILED
LiquidCrystal_I2C lcd(0x27, 16, 2); // Change 0x27 to the correct I2C address for your LCD
// Just to avoid spamming
unsigned long lastKeyPress = 0;
unsigned long keyDelay = 200;
void setup() {
Serial.begin(9600);
if (!keyPad.begin()) {
Serial.print("Cannot connect to I2C keypad.\n");
while(1);
}
keyPad.loadKeyMap(keypad_layout);
lcd.init();
lcd.backlight(); // You can remove this line if your LCD doesn't have backlight control
lcd.setCursor(0, 0);
lcd.print("Press a key:");
//lcd.setCursor(0, 3);
// lcd.print("HAVE A NICE DAY:");
lcd.setCursor(0, 3);
lcd.print("PROJECT BY ARVIND:");
}
void loop() {
if (keyPad.isPressed() && deltaTime(lastKeyPress) > keyDelay) {
lastKeyPress = millis();
char ch = keyPad.getChar();
Serial.println("Pressed: " + String(ch));
lcd.setCursor(0, 1);
lcd.print("Pressed: " + String(ch));
}
// Makes the code run faster
delay(10);
}