#include <Keypad.h>
// Pin configuration for the 3x3 button matrix
const byte rowPins[3] = {2, 3, 4}; // Rows connected to pins 2, 3, 4
const byte colPins[3] = {5, 6, 7}; // Columns connected to pins 5, 6, 7
// Define keypad layout
char keys[3][3] = {
{'1', '2', '3'},
{'4', '5', '6'},
{'7', '8', '9'}
};
// Create Keypad object
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, 3, 3);
void setup() {
Serial.begin(9600); // Initialize serial communication
}
void loop() {
// Scan the button matrix
char key = keypad.getKey();
if (key) {
// Send the key press to the computer
Serial.print("Key Pressed: ");
Serial.println(key);
delay(100); // Delay for key press duration
}
}