-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKeyboard.cpp
100 lines (73 loc) · 1.6 KB
/
Keyboard.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
* Keyboard.cpp
*
* Created on: Jul 3, 2019
* Author: root
*/
#include <avr/io.h> /* Include AVR std. library file */
#include <util/delay.h> /* Include inbuilt defined Delay header file */
#include "Keyboard.h"
Keyboard::Keyboard(GPIO *l1, GPIO *l2, GPIO *l3,GPIO *l4,GPIO *c1,GPIO *c2,GPIO *c3,GPIO *c4 ){
key = 'N';
l[0] = l1;
l[1] = l2;
l[2] = l3;
l[3] = l4;
c[0] = c1;
c[1] = c2;
c[2] = c3;
c[3] = c4;
}
bool Keyboard::Percorre(){
bool teste = true;
for (int ti = 0; ti<4; ti++)
{
//Alterna o estado dos pinos das linhas
l[0]->set(false);
l[1]->set(false);
l[2]->set(false);
l[3]->set(false);
l[ti]->set(true);
//Verifica se alguma tecla da coluna 1 foi pressionada
if (c[0]->get())
{
Key(ti, 0);
while(c[0]->get());
teste = false;
}
//Verifica se alguma tecla da coluna 2 foi pressionada
if (c[1]->get())
{
Key(ti, 1);
while(c[1]->get());
teste = false;
}
//Verifica se alguma tecla da coluna 3 foi pressionada
if (c[2]->get())
{
Key(ti, 2);
while(c[2]->get());
teste = false;
}
//Verifica se alguma tecla da coluna 4 foi pressionada
if (c[3]->get())
{
Key(ti, 3);
while(c[3]->get());
teste = false;
}
}
_delay_ms(10);
return teste;
}
char Keyboard::retKey(){
return key;
}
void Keyboard::Key(int i, int j) {
unsigned char keypad[4][4] = { {'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}};
key = keypad[i][j];
//return key;
}