/*
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 SHIFT_PIN = 24;
const int RS = 12, EN = 11, D4 = 10, D5 = 9, D6 = 8, D7 = 7;
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 KEY_CHAR[] = {
'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', ' '
};
struct keyData {
int keyPin;
char upperCase;
char lowerCase;
};
keyData KEYS[NUM_BTNS];
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(KEYS[i].keyPin);
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 advanceCursor() {
column++;
if (column == 16) {
column = 0;
row++;
if (row == 2) row = 0;
}
}
void setup() {
Serial.begin(115200);
lcd.begin(16, 2);
for (int pin = 0; pin < NUM_BTNS; pin++) {
KEYS[pin].keyPin = BTN_PINS[pin];
KEYS[pin].upperCase = KEY_CHAR[pin];
KEYS[pin].lowerCase = KEYS[pin].upperCase + 32;
pinMode(KEYS[pin].keyPin, INPUT_PULLUP);
oldBtnState[pin] = HIGH;
}
pinMode(SHIFT_PIN, INPUT_PULLUP);
Serial.println("Top row:");
//Serial.println("q w e r t y u i o p a s d Clear");
for (int i = 0; i < 13; i++) {
Serial.print(KEYS[i].upperCase);
Serial.print(' ');
}
Serial.println("Clear");
Serial.println("Bottom row:");
//Serial.println("f g h j k l z x c v b n m Space");
for (int i = 14; i < 27; i++) {
Serial.print(KEYS[i].upperCase);
Serial.print(' ');
}
Serial.println("Space");
lcd.setCursor(1, 0);
lcd.print("Mega Keyboard");
lcd.setCursor(5, 1);
lcd.print("V1.00");
delay(2000);
lcd.clear();
}
void loop() {
bool isShift = !digitalRead(SHIFT_PIN);
int btnNumber = checkButtons();
if (btnNumber > 0) {
int btnIdx = btnNumber - 1;
if (KEYS[btnIdx].upperCase == char(255)) { // "clear"
lcd.clear();
column = 0;
row = 0;
} else if (KEYS[btnIdx].upperCase == char(32)) { // "space"
lcd.setCursor(column, row);
lcd.print(' ');
//Serial.print(' ');
advanceCursor();
} else {
lcd.setCursor(column, row);
char displayChar = isShift ? KEYS[btnIdx].upperCase : KEYS[btnIdx].lowerCase;
lcd.print(displayChar);
//Serial.print(displayChar);
advanceCursor();
}
}
}SHIFT
CLEAR
SPACE