#include <Key.h>
#include <Keypad.h>
const byte ROWS = 4;
const byte COLS = 4;
byte rowPins[ROWS] = {5, 4, 3, 2}; // Array definition.
byte colPins[COLS] = {6, 7, 8, 9};
char buttons[ROWS][COLS] = {
{'1', '2', '3', 'A'}, // 1st row
{'4', '5', '6', 'B'}, // 2nd row
{'7', '8', '9', 'C'}, // 3rd row
{'*', '0', '#', 'D'} // 4th row
}; // 2D array of character type variables.
Keypad pad = Keypad(makeKeymap(buttons), rowPins, colPins, ROWS, COLS); // create an instance (with name pad) of the object Keypad, which is made available by the Keypad library.
void setup() {
// put your setup code here, to run once:
// Initialize Serial Monitor:
Serial.begin(9600);
}
void loop () {
// put your main code here, to run repeatedly:
char result = pad.getKey();
if (result) { // if result is non-zero; could also put (result!=0)
Serial.println(result);
}
}