#include <Keypad.h>
#include <LiquidCrystal_I2C.h>
// Define Keypad Rows and Columns
const byte ROWS = 4;
const byte COLS = 4;
// This should match your actual keypad layout
char keys[ROWS][COLS] = {
{ '1', '2', '3', 'A' },
{ '4', '5', '6', 'B' },
{ '7', '8', '9', 'C' },
{ '*', '0', '#', 'D' }
};
LiquidCrystal_I2C lcd(0x27, 16, 2);
// Change these to match your actual ESP32 GPIO connections
byte colPins[COLS] = {21, 4, 3, 2}; // GPIOs connected to keypad columns
byte rowPins[ROWS] = {20, 8, 9, 10}; // GPIOs connected to keypad rows
Keypad customKeypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
void setup(){
Serial.begin(9600);
lcd.init();
lcd.backlight();
}
void loop(){
char customKey = customKeypad.getKey();
if (customKey != NO_KEY){
Serial.println(customKey);
lcd.clear();
lcd.setCursor(0,0);
lcd.print(customKey);
}
delay(100);
}
Loading
xiao-esp32-c3
xiao-esp32-c3