-
Notifications
You must be signed in to change notification settings - Fork 0
/
Teensy_IR_computer_remote.pde
335 lines (244 loc) · 6.29 KB
/
Teensy_IR_computer_remote.pde
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
#include <IRremote.h>
#include <IRremoteInt.h>
#include <IRremote.h>
#define CENTER 50135550
#define UP 50190375
#define RIGHT 50157735
#define DOWN 50198535
#define LEFT 50165895
#define POWER 50153655
#define MUTE 50137335
#define RECALL 50149575
#define EXIT 50141925
#define ENTER 50194455
#define ZERO 50135295
#define HUNDRED 50155695
const int RECV_PIN = 6;
IRrecv irrecv(RECV_PIN);
decode_results results;
boolean capToggleState = true;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
irrecv.blink13(true);
}
void loop() {
if (irrecv.decode(&results)) {
if (results.decode_type == NEC) {
if (results.value == CENTER){
ctrlAltDelet();
}
if (results.value == UP){
ScreenUp();
}
if (results.value == RIGHT){
ScreenRight();
}
if (results.value == DOWN){
ScreenDown();
}
if (results.value == LEFT){
ScreenLeft();
}
if (results.value == EXIT){
enter();
}
if (results.value == ENTER){
insert();
}
if (results.value == RECALL){
AltTab();
}
if (results.value == HUNDRED){
CtrlA();
}
if (results.value == ZERO){
CtrlZ();
}
if (results.value == ZERO){
CtrlZ();
}
if (results.value == MUTE){
esc();
}
if (results.value == POWER){
CapsLock();
}
Serial.print("NEC: ");
}
else if (results.decode_type == SONY) {
Serial.print("SONY: ");
}
else if (results.decode_type == RC5) {
Serial.print("RC5: ");
}
else if (results.decode_type == RC6) {
Serial.print("RC6: ");
}
else if (results.decode_type == UNKNOWN) {
Serial.print("UNKNOWN: ");
}
Serial.println(results.value, HEX);
Serial.println(results.value);
//Serial.println(results.value);
irrecv.resume(); // Receive the next value
}
}
void ctrlAltDelet(){
// press and hold CTRL
Keyboard.set_modifier(MODIFIERKEY_CTRL);
Keyboard.send_now();
// press ALT while still holding CTRL
Keyboard.set_modifier(MODIFIERKEY_CTRL | MODIFIERKEY_ALT);
Keyboard.send_now();
// press DELETE, while CLTR and ALT still held
Keyboard.set_key1(KEY_DELETE);
Keyboard.send_now();
// release all the keys at the same instant
Keyboard.set_modifier(0);
Keyboard.set_key1(0);
Keyboard.send_now();
}
void insert(){
Keyboard.set_key1(KEY_INSERT);
Keyboard.send_now();
Keyboard.set_key1(0);
Keyboard.send_now();
}
void esc(){
Keyboard.set_key1(KEY_ESC);
Keyboard.send_now();
Keyboard.set_key1(0);
Keyboard.send_now();
}
void enter(){
Keyboard.set_key1(KEY_ENTER);
Keyboard.send_now();
Keyboard.set_key1(0);
Keyboard.send_now();
}
void CapsLock(){
if(capToggleState){
Keyboard.set_key2(KEY_CAPS_LOCK);
Keyboard.send_now();
capToggleState = false;
}
else {
Keyboard.set_key1(KEY_CAPS_LOCK);
Keyboard.send_now();
Keyboard.set_key2(0);
Keyboard.send_now();
capToggleState = true;
}
}
void CtrlZ(){
// press and hold CTRL
Keyboard.set_modifier(MODIFIERKEY_CTRL);
Keyboard.send_now();
// press DELETE, while CLTR and ALT still held
Keyboard.set_key1(KEY_Z);
Keyboard.send_now();
// release all the keys at the same instant
Keyboard.set_modifier(0);
Keyboard.set_key1(0);
Keyboard.send_now();
}
void CtrlA(){
// press and hold CTRL
Keyboard.set_modifier(MODIFIERKEY_CTRL);
Keyboard.send_now();
// press DELETE, while CLTR and ALT still held
Keyboard.set_key1(KEY_A);
Keyboard.send_now();
// release all the keys at the same instant
Keyboard.set_modifier(0);
Keyboard.set_key1(0);
Keyboard.send_now();
}
void AltTab(){
// press and hold CTRL
Keyboard.set_modifier(MODIFIERKEY_ALT);
Keyboard.send_now();
// press DELETE, while CLTR and ALT still held
Keyboard.set_key1(KEY_TAB);
Keyboard.send_now();
// release all the keys at the same instant
Keyboard.set_modifier(0);
Keyboard.set_key1(0);
Keyboard.send_now();
}
void ScreenUp(){
// press and hold CTRL
Keyboard.set_modifier(MODIFIERKEY_CTRL);
Keyboard.send_now();
// press ALT while still holding CTRL
Keyboard.set_modifier(MODIFIERKEY_CTRL | MODIFIERKEY_ALT);
Keyboard.send_now();
// press DELETE, while CLTR and ALT still held
Keyboard.set_key1(KEY_UP);
Keyboard.send_now();
// release all the keys at the same instant
Keyboard.set_modifier(0);
Keyboard.set_key1(0);
Keyboard.send_now();
}
void ScreenDown(){
// press and hold CTRL
Keyboard.set_modifier(MODIFIERKEY_CTRL);
Keyboard.send_now();
// press ALT while still holding CTRL
Keyboard.set_modifier(MODIFIERKEY_CTRL | MODIFIERKEY_ALT);
Keyboard.send_now();
// press DELETE, while CLTR and ALT still held
Keyboard.set_key1(KEY_DOWN);
Keyboard.send_now();
// release all the keys at the same instant
Keyboard.set_modifier(0);
Keyboard.set_key1(0);
Keyboard.send_now();
}
void ScreenRight(){
// press and hold CTRL
Keyboard.set_modifier(MODIFIERKEY_CTRL);
Keyboard.send_now();
// press ALT while still holding CTRL
Keyboard.set_modifier(MODIFIERKEY_CTRL | MODIFIERKEY_ALT);
Keyboard.send_now();
// press DELETE, while CLTR and ALT still held
Keyboard.set_key1(KEY_RIGHT);
Keyboard.send_now();
// release all the keys at the same instant
Keyboard.set_modifier(0);
Keyboard.set_key1(0);
Keyboard.send_now();
}
void ScreenLeft(){
// press and hold CTRL
Keyboard.set_modifier(MODIFIERKEY_CTRL);
Keyboard.send_now();
// press ALT while still holding CTRL
Keyboard.set_modifier(MODIFIERKEY_CTRL | MODIFIERKEY_ALT);
Keyboard.send_now();
// press DELETE, while CLTR and ALT still held
Keyboard.set_key1(KEY_LEFT);
Keyboard.send_now();
// release all the keys at the same instant
Keyboard.set_modifier(0);
Keyboard.set_key1(0);
Keyboard.send_now();
}
/*
NEC: 2FD01FE center 50135550
NEC: 2FDD827 up 50190375
NEC: 2FD58A7 right 50157735
NEC: 2FDF807 down 50198535
NEC: 2FD7887 left 50165895
NEC: 2FD48B7 power 50153655
NEC: 2FD08F7 mute 50137335
NEC: 2FD38C7 recall 50149575
NEC: 2FD1AE5 exit 50141925
NEC: 2FDE817 enter 50194455
NEC: 2FD00FF zero 50135295
NEC: 2FD50AF hundred 50155695
*/