#include <Keypad.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
#define p_pin A0
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{ '1', '2', '3', 'A' },
{ '4', '5', '6', 'B' },
{ '7', '8', '9', 'C' },
{ '*', '0', '#', 'D' }
};
byte colPins[COLS] = { 5, 4, 3, 2 };
byte rowPins[ROWS] = { 9, 8, 7, 6 };
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
void setup() {
pinMode(p_pin, INPUT);
lcd.init();
lcd.backlight();
lcd.setCursor(0,0);
lcd.print("Press a Key:");
delay(2000);
}
void loop() {
int contrastValue = analogRead(p_pin);
int contrast = map(contrastValue, 0, 1023, 0, 255);
// lcd.command(0x21);
// lcd.command(0x80 | contrast);
// lcd.command(0x20);
char key = keypad.getKey();
if (key) {
lcd.setCursor(0,1);
lcd.print("key: ");
lcd.print(key);
// Serial.println(key);
}
}