/*
Wokwi | questions
Why wont the bottom keys work at all?
Reix
Friday, November 21, 2025 6:26 PM
all the keys on the bottom dont work
https://wokwi.com/projects/448094518379741185
*/
#include <LiquidCrystal.h>
const int NUM_BTNS = 28;
const int BTN_PINS[] = {
53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40,
26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39
};
const char BTN_CHARS[] = {
'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', 'a', 's', 'd', 255,
'f', 'g', 'h', 'j', 'k', 'l', 'z', 'x', 'c', 'v', 'b', 'n', 'm', ' '
};
const int RS = 12, EN = 11, D4 = 10, D5 = 9, D6 = 8, D7 = 7;
int column = 0;
int row = 0;
int btnState[NUM_BTNS];
int oldBtnState[NUM_BTNS];
LiquidCrystal lcd(RS, EN, D4, D5, D6, D7);
int checkButtons() {
int btnNumber = 0;
for (int i = 0; i < NUM_BTNS; i++) {
// check each button
btnState[i] = digitalRead(BTN_PINS[i]);
if (btnState[i] != oldBtnState[i]) { // if it changed
oldBtnState[i] = btnState[i]; // remember state for next time
if (btnState[i] == LOW) { // was just pressed
btnNumber = i + 1;
//Serial.print("Button ");
//Serial.print(btnNumber);
//Serial.println(" pressed.");
} else { // was just released
btnNumber = -1;
}
delay(20); // debounce
}
}
return btnNumber;
}
void setup() {
Serial.begin(115200);
lcd.begin(16, 2);
for (int pin = 0; pin < NUM_BTNS; pin++) {
pinMode(BTN_PINS[pin], INPUT_PULLUP);
oldBtnState[pin] = HIGH;
}
Serial.println("Top row:");
Serial.println("q w e r t y u i o p a s d Clear");
Serial.println("Bottom row:");
Serial.println("f g h j k l z x c v b n m Space");
lcd.setCursor(2, 0);
lcd.print("Mega Keypad");
lcd.setCursor(5, 1);
lcd.print("V1.00");
delay(2000);
lcd.clear();
}
void loop() {
int btnNum = checkButtons();
if (btnNum > 0) {
if (BTN_CHARS[btnNum - 1] == char(255)) {
lcd.clear();
column = 0;
row = 0;
} else {
lcd.setCursor(column, row);
lcd.print(BTN_CHARS[btnNum - 1]);
//Serial.print(BTN_CHARS[btnNum - 1]);
column++;
if (column == 16) {
column = 0;
row++;
if (row == 2) row = 0;
}
}
}
}