#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
// I2C LCD 20x4 at address 0x27
LiquidCrystal_I2C lcd(0x27, 20, 4);
// Keypad setup
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 rowPins[ROWS] = {12, 11, 10, 9};
byte colPins[COLS] = {7, 6, 5, 4};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
void setup() {
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("STM32 Keypad Input");
}
void loop() {
char key = keypad.getKey();
if (key) {
lcd.setCursor(0, 2); // Row 2 of 20x4
lcd.print("Pressed: ");
lcd.print(key);
lcd.print(" "); // Clear trail
delay(300);
}
}