// Pin assignments for the columns and rows
const int colPins[3] = {5, 18, 19};
const int rowPins[2] = {16, 17};
bool keyStates[2][3];
void setup() {
Serial.begin(115200);
for (int col = 0; col < 3; col++) {
pinMode(colPins[col], OUTPUT);
digitalWrite(colPins[col], HIGH);
}
// Set row pins as inputs
for (int row = 0; row < 2; row++) {
pinMode(rowPins[row], INPUT);
}
}
void loop() {
// Scan the keyboard matrix
for (int col = 0; col < 3; col++) {
digitalWrite(colPins[col], LOW);
for (int row = 0; row < 2; row++) {
pinMode(rowPins[row], OUTPUT);
digitalWrite(rowPins[row], LOW);
delay(1);
pinMode(rowPins[row], INPUT);
keyStates[row][col] = digitalRead(rowPins[row]);
}
digitalWrite(colPins[col], HIGH);
}
Serial.println("Key States:");
for (int row = 0; row < 2; row++) {
for (int col = 0; col < 3; col++) {
Serial.print(keyStates[row][col] ? "Pressed " : "Released ");
}
Serial.println();
}
Serial.println();
delay(500);
}