#include <Keypad.h>
//Setting the number of rows and
//columns on a keypad.
//Arranging the numbers and letters in
//a matrix.
const int ROWS = 4;
const int COLS = 4;
char keysymb [ROWS] [COLS]=
{
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
//Configurando los puertos por cada columna y linea
byte colPins[COLS] = { 5, 4, 3, 2};
byte rowPins[ROWS] = { 9, 8, 7, 6};
//Configurando el panel numérico
Keypad keypad = Keypad(makeKeymap(keysymb), rowPins, colPins, ROWS, COLS);
void setup()
{
portInit();
}
void loop()
{
PrintNum();
}
//Assigns a mode, INPUT or OUTPUT, to all of the ports that the keypad is connected.
//Initializes the Serial Monitor to print material onto the console.
void portInit()
{
Serial.begin(115200);
for (int i = 0; i < 4; i++)
{
pinMode(rowPins[i], INPUT);
}
for (int i= 0; i < 4; i++)
{
pinMode(colPins[i], INPUT);
}
}
void PrintNum()
{
char whichcharsym;
//keypad.getKey() – waits for a user to input a value.
//whichcharsym is a variable that will store a value.
whichcharsym = keypad.getKey();
if(whichcharsym != NO_KEY)
{
//The serial monitor will output a value every time the keypad has been pressed.
Serial.print(whichcharsym);
}
}