-
Notifications
You must be signed in to change notification settings - Fork 0
/
keyboard-example.c
117 lines (94 loc) · 2.21 KB
/
keyboard-example.c
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include <Keyboard.h>
//Pin layout here
const int rowPin0 = 0;
const int rowPin1 = 1;
const int rowPin2 = 2;
const int rowPin3 = 3;
const int columnPin0 = 4;
const int columnPin1 = 5;
const int columnPin2 = 6;
void setup(){
pinMode(rowPin0, OUTPUT);
digitalWrite(rowPin0, HIGH);
pinMode(rowPin1, OUTPUT);
digitalWrite(rowPin1, HIGH);
pinMode(rowPin2, OUTPUT);
digitalWrite(rowPin2, HIGH);
pinMode(rowPin3, OUTPUT);
digitalWrite(rowPin3, HIGH);
pinMode(columnPin0, INPUT_PULLUP);
pinMode(columnPin1, INPUT_PULLUP);
pinMode(columnPin2, INPUT_PULLUP);
}
void loop(){
// Do row 0
digitalWrite(rowPin0, HIGH);
digitalWrite(rowPin1, LOW);
digitalWrite(rowPin2, LOW);
digitalWrite(rowPin3, LOW);
if (digitalRead(columnPin0) == LOW){
Keyboard.set_key1(KEY_1);
} else {
Keyboard.set_key1(0);
}
Keyboard.send_now();
if (digitalRead(columnPin1) == LOW){
Keyboard.set_key1(KEY_2);
} else {
Keyboard.set_key1(0);
}
Keyboard.send_now();
if (digitalRead(columnPin2) == LOW){
Keyboard.set_key1(KEY_3);
} else {
Keyboard.set_key1(0);
}
Keyboard.send_now();
// Do row 1
digitalWrite(rowPin0, LOW);
digitalWrite(rowPin1, HIGH);
digitalWrite(rowPin2, LOW);
digitalWrite(rowPin3, LOW);
if (digitalRead(columnPin0) == LOW){
Keyboard.set_key1(KEY_4);
} else {
Keyboard.set_key1(0);
}
Keyboard.send_now();
if (digitalRead(columnPin1) == LOW){
Keyboard.set_key1(KEY_5);
} else {
Keyboard.set_key1(0);
}
Keyboard.send_now();
if (digitalRead(columnPin2) == LOW){
Keyboard.set_key1(KEY_6);
} else {
Keyboard.set_key1(0);
}
Keyboard.send_now();
// Do row 2
digitalWrite(rowPin0, LOW);
digitalWrite(rowPin1, LOW);
digitalWrite(rowPin2, HIGH);
digitalWrite(rowPin3, LOW);
if (digitalRead(columnPin0) == LOW){
Keyboard.set_key1(KEY_7);
} else {
Keyboard.set_key1(0);
}
Keyboard.send_now();
if (digitalRead(columnPin1) == LOW){
Keyboard.set_key1(KEY_8);
} else {
Keyboard.set_key1(0);
}
Keyboard.send_now();
if (digitalRead(columnPin2) == LOW){
Keyboard.set_key1(KEY_9);
} else {
Keyboard.set_key1(0);
}
Keyboard.send_now();
delay(120);
}