// importa biblioteca Keypad
#include <Keypad.h>
#define led 32
// define numero de linhas
const uint8_t ROWS = 4;
// define numero de colunas
const uint8_t COLS = 4;
// define as distribuicoes das teclas
char teclas[ROWS][COLS] = {
{ '1', '2', '3', 'A' },
{ '4', '5', '6', 'B' },
{ '7', '8', '9', 'C' },
{ '*', '0', '#', 'D' }
};
// pinos correspondentes da linha
uint8_t colPins[COLS] = { 16, 4, 2, 15 };
// pinos correspondentes da coluna
uint8_t rowPins[ROWS] = { 19, 18, 5, 17 };
// instanciando keypad
Keypad keypad = Keypad(makeKeymap(teclas), rowPins, colPins, ROWS, COLS);
void setup() {
Serial.begin(9600);
pinMode(led, OUTPUT);
}
void loop() {
// tecla pressionada
char tecla = keypad.getKey();
// verifica se pressionou uma tecla
if (tecla) {
// envia para a porta serial
Serial.println(tecla);
if (tecla=='1')
{
digitalWrite(led,!digitalRead(led));
}
}
}