-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-Clavier.ino
56 lines (48 loc) · 1001 Bytes
/
test-Clavier.ino
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
// TEST-CLAVIER
// PBA 2018-05-03
const byte KbdCol[4]={4,5,6,7};
const byte KbdRow[4]={8,9,10,11};
const byte KbdOut[4][4]={{'1','4','7','*'},{'2','5','8','0'},{'3','6','9','#'},{'A','B','C','D'}};
void keyboardInit(void)
{
for(byte col=0; col<4; col++)
pinMode(KbdCol[col],OUTPUT);
for(byte row=0; row<4; row++)
pinMode(KbdRow[row],INPUT_PULLUP);
}
char keyboardScan(void)
{
for(byte col=0; col<4; col++)
{
for(byte col2=0; col2<4; col2++)
digitalWrite(KbdCol[col2],HIGH);
digitalWrite(KbdCol[col],LOW);
for(byte row=0; row<4; row++)
if(!digitalRead(KbdRow[row]))
return(KbdOut[col][row]);
}
return(0);
}
char keyboardRead()
{
static char lastKey=0;
char newKey=keyboardScan();
if(newKey!=lastKey)
{
delay(50); // Anti rebond
lastKey=newKey;
return(newKey);
}
return(0);
}
void setup()
{
Serial.begin(9600);
keyboardInit();
}
void loop()
{
char c = keyboardRead();
if(c) Serial.println(c);
delay(100);
}