// https://forum.arduino.cc/t/teclado-matricial-sem-biblioteca-deboucing/1269509
/* Projeto de Tranca Eletrônica
Autor: Igor Henrique Moreira Lusquinho
Data:06/06/2024
*/
#define buzzer 10
#define trava 13
unsigned short linhas[] = {9, 8, 7, 6};
unsigned short colunas[] = {5, 4, 3, 2};
char keypad[] = {'1', '2', '3', 'A', '4', '5', '6', 'B', '7', '8', '9', 'C', '*', '0', '#', 'D'};
int btn = 0;
void matricial();
void display();
boolean flag_btn = true;
//----------------------------------------------------------------------
void setup() {
Serial.begin(9600);
pinMode(buzzer, OUTPUT);
pinMode(trava, INPUT);
for (int i = 0; i < 4; i++)
{
pinMode(linhas[i], OUTPUT);
pinMode(colunas[i], INPUT);
digitalWrite(linhas[i], HIGH);
digitalWrite(colunas[i], HIGH);
}
}
//---------------------------------------------------------------------- -
void loop() {
matricial();
}
//---------------------------------------------------------------------- -
void matricial() {
for (short l = 0; l < 4; l++) {
digitalWrite(linhas[l], LOW);
for (short c = 0; c < 4; c++) {
while (!digitalRead(colunas[c]) ) {
btn = (l * 4) + (c);
flag_btn = false;
}
if (flag_btn == false) {
Serial.print(keypad[btn]);
flag_btn = true;
}
}
digitalWrite(linhas[l], HIGH);
}
}