#include <Keypad.h>
// Define the number of rows and columns of the keypad
const byte ROWS = 4;
const byte COLS = 4;
// Define the keymap
char keys[ROWS][COLS] = {
{'1', '2', '3', '+'},
{'4', '5', '6', '-'},
{'7', '8', '9', '*'},
{'@', '0', '#', '%'}
};
// Define the pin connections for rows and columns
byte rowPins[ROWS] = {9, 8, 7, 6};
byte colPins[COLS] = {5, 4, 3, 2};
// Create an instance of the Keypad class
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
void setup() {
// Begin serial communication at a baud rate of 9600
Serial.begin(9600);
}
void loop() {
// Get the key pressed
char key = keypad.getKey();
// If a key is pressed, print it to the Serial Monitor
if (key) {
Serial.print("Key pressed: ");
Serial.println(key);
}
}