#include <Keypad.h>
// Define the keypad layout (4x4 matrix)
const byte ROW_NUM = 4; // four rows
const byte COL_NUM = 4; // four columns
// Define the row and column pinouts
char keys[ROW_NUM][COL_NUM] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte pin_rows[ROW_NUM] = {0, 1, 2, 3}; // Connect to the row pinouts
byte pin_column[COL_NUM] = {4, 5, 8, 9}; // Connect to the column pinouts
// Create the keypad object
Keypad keypad = Keypad(makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COL_NUM);
void setup() {
Serial.begin(115200); // Start Serial Monitor at 115200 baud
Serial.println("Enter a number:");
}
void loop() {
char key = keypad.getKey();
if (key) {
Serial.print("You pressed: ");
Serial.println(key);
}
}