-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStreamDeck.ino
303 lines (279 loc) · 10.2 KB
/
StreamDeck.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
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
#include <Adafruit_NeoPixel.h> // https://github.com/adafruit/Adafruit_NeoPixel (1.12.0)
#include "Keypad.h" // https://github.com/Nullkraft/Keypad (3.2.1)
#include <Keyboard.h> // https://github.com/arduino-libraries/Keyboard (1.0.6)
#include "Encoder.h" // https://github.com/PaulStoffregen/Encoder (1.4.4)
#include "Button.h" // https://github.com/madleech/Button (Initial Release)
#include "id_teclas.h" // Dependiente del proyecto
// Distribucion de las entradas digitales; usamos "byte" en vez de "int" por dependecia de la libreria.
#define filas_keypad 3
#define columnas_keypad 3
byte pines_fila[filas_keypad] = { 5,6,7 };
byte pines_columna[columnas_keypad] = { 8,9,10 };
byte pin_neopixel = 16;
byte pinA_encoder = 2;
byte pinB_encoder = 3;
byte pinBoton_encoder = 4;
//Variables internas del programa.
int estado_encoder_0 = 0;
int capa_teclado = 0;
char pulsadores_capa1[filas_keypad][columnas_keypad] = {
{'a', 'b', 'c'},
{'d', 'e', 'f'},
{'g', 'h', 'i'} };
// Creacion de los objetos
Keypad botones = Keypad(makeKeymap(pulsadores_capa1), pines_fila, pines_columna, filas_keypad, columnas_keypad);
Adafruit_NeoPixel neopi(1, pin_neopixel, NEO_GRBW + NEO_KHZ800);
Encoder codificador(pinA_encoder, pinB_encoder);
Button boton_encoder(pinBoton_encoder);
void test_botones();
void eventos_botones(KeypadEvent boton_pulsado);
void seleccion_capa();
void setup() {
Serial.begin(9600);
Keyboard.begin();
botones.addEventListener(eventos_botones);
boton_encoder.begin();
neopi.begin();
neopi.setPixelColor(0, 255, 0, 0);
neopi.show();
}
void loop() {
if (boton_encoder.pressed()) {
seleccion_capa();
}
char boton_pulsado = botones.getKey();
if (boton_pulsado) {
Serial.println(boton_pulsado);
}
//Serial.print(boton_encoder.read());
}
void test_botones() { // Funcion para probar el estado de los botones del keypad
char test_tecla = botones.getKey();
if (test_tecla) {
Serial.println(test_tecla);
}
}
void seleccion_capa() {
int estado_encoder_1 = estado_encoder_0;
bool capa_elegida = false;
while (capa_elegida == false) {
estado_encoder_1 = codificador.read();
if (estado_encoder_1 > estado_encoder_0 && capa_teclado < 2) {
capa_teclado++;
}
else if (estado_encoder_1 < estado_encoder_0 && capa_teclado > 0) {
capa_teclado--;
}
estado_encoder_0 = estado_encoder_1;
/*Serial.print("la capa es ");
Serial.print(capa_teclado);*/
delay(300);
if (capa_teclado == 0) {
neopi.setPixelColor(0, 255, 0, 0);
}
else if (capa_teclado == 1) {
neopi.setPixelColor(0, 0, 255, 0);
}
else if (capa_teclado == 2) {
neopi.setPixelColor(0, 0, 0, 255);
}
neopi.show();
if (boton_encoder.pressed()) {
capa_elegida = true;
}
}
}
void eventos_botones(KeypadEvent boton_pulsado) {
//CAPA ROJA
if (boton_pulsado == 'a' && botones.getState() == PRESSED && capa_teclado == 0) {
Keyboard.press(TECLA_CTRL_IZQUIERDO);
Keyboard.press(TECLA_ALT_DERECHO);
Keyboard.press(TECLA_SHIFT_DERECHO);
Keyboard.press(TECLA_F1);
Keyboard.releaseAll();
}
if (boton_pulsado == 'b' && botones.getState() == PRESSED && capa_teclado == 0) {
Keyboard.press(TECLA_CTRL_IZQUIERDO);
Keyboard.press(TECLA_ALT_DERECHO);
Keyboard.press(TECLA_SHIFT_DERECHO);
Keyboard.press(TECLA_F2);
Keyboard.releaseAll();
}
if (boton_pulsado == 'c' && botones.getState() == PRESSED && capa_teclado == 0) {
Keyboard.press(TECLA_CTRL_IZQUIERDO);
Keyboard.press(TECLA_ALT_DERECHO);
Keyboard.press(TECLA_SHIFT_DERECHO);
Keyboard.press(TECLA_F3);
Keyboard.releaseAll();
}
if (boton_pulsado == 'd' && botones.getState() == PRESSED && capa_teclado == 0) {
Keyboard.press(TECLA_CTRL_IZQUIERDO);
Keyboard.press(TECLA_ALT_DERECHO);
Keyboard.press(TECLA_SHIFT_DERECHO);
Keyboard.press(TECLA_F4);
Keyboard.releaseAll();
}
if (boton_pulsado == 'e' && botones.getState() == PRESSED && capa_teclado == 0) {
Keyboard.press(TECLA_CTRL_IZQUIERDO);
Keyboard.press(TECLA_ALT_DERECHO);
Keyboard.press(TECLA_SHIFT_DERECHO);
Keyboard.press(TECLA_F5);
Keyboard.releaseAll();
}
if (boton_pulsado == 'f' && botones.getState() == PRESSED && capa_teclado == 0) {
Keyboard.press(TECLA_CTRL_IZQUIERDO);
Keyboard.press(TECLA_ALT_DERECHO);
Keyboard.press(TECLA_SHIFT_DERECHO);
Keyboard.press(TECLA_F6);
Keyboard.releaseAll();
}
if (boton_pulsado == 'g' && botones.getState() == PRESSED && capa_teclado == 0) {
Keyboard.press(TECLA_CTRL_IZQUIERDO);
Keyboard.press(TECLA_ALT_DERECHO);
Keyboard.press(TECLA_SHIFT_DERECHO);
Keyboard.press(TECLA_F7);
Keyboard.releaseAll();
}
if (boton_pulsado == 'h' && botones.getState() == PRESSED && capa_teclado == 0) {
Keyboard.press(TECLA_CTRL_IZQUIERDO);
Keyboard.press(TECLA_ALT_DERECHO);
Keyboard.press(TECLA_SHIFT_DERECHO);
Keyboard.press(TECLA_F8);
Keyboard.releaseAll();
}
if (boton_pulsado == 'i' && botones.getState() == PRESSED && capa_teclado == 0) {
Keyboard.press(TECLA_CTRL_IZQUIERDO);
Keyboard.press(TECLA_ALT_DERECHO);
Keyboard.press(TECLA_SHIFT_DERECHO);
Keyboard.press(TECLA_F9);
Keyboard.releaseAll();
}
// CAPA VERDE
if (boton_pulsado == 'a' && botones.getState() == PRESSED && capa_teclado == 1) {
Keyboard.press(TECLA_CTRL_IZQUIERDO);
Keyboard.press(TECLA_ALT_DERECHO);
Keyboard.press(TECLA_SHIFT_DERECHO);
Keyboard.press('A');
Keyboard.releaseAll();
}
if (boton_pulsado == 'b' && botones.getState() == PRESSED && capa_teclado == 1) {
Keyboard.press(TECLA_CTRL_IZQUIERDO);
Keyboard.press(TECLA_ALT_DERECHO);
Keyboard.press(TECLA_SHIFT_DERECHO);
Keyboard.press('S');
Keyboard.releaseAll();
}
if (boton_pulsado == 'c' && botones.getState() == PRESSED && capa_teclado == 1) {
Keyboard.press(TECLA_CTRL_IZQUIERDO);
Keyboard.press(TECLA_ALT_DERECHO);
Keyboard.press(TECLA_SHIFT_DERECHO);
Keyboard.press('D');
Keyboard.releaseAll();
}
if (boton_pulsado == 'd' && botones.getState() == PRESSED && capa_teclado == 1) {
Keyboard.press(TECLA_CTRL_IZQUIERDO);
Keyboard.press(TECLA_ALT_DERECHO);
Keyboard.press(TECLA_SHIFT_DERECHO);
Keyboard.press('F');
Keyboard.releaseAll();
}
if (boton_pulsado == 'e' && botones.getState() == PRESSED && capa_teclado == 1) {
Keyboard.press(TECLA_CTRL_IZQUIERDO);
Keyboard.press(TECLA_ALT_DERECHO);
Keyboard.press(TECLA_SHIFT_DERECHO);
Keyboard.press('G');
Keyboard.releaseAll();
}
if (boton_pulsado == 'f' && botones.getState() == PRESSED && capa_teclado == 1) {
Keyboard.press(TECLA_CTRL_IZQUIERDO);
Keyboard.press(TECLA_ALT_DERECHO);
Keyboard.press(TECLA_SHIFT_DERECHO);
Keyboard.press('H');
Keyboard.releaseAll();
}
if (boton_pulsado == 'g' && botones.getState() == PRESSED && capa_teclado == 1) {
Keyboard.press(TECLA_CTRL_IZQUIERDO);
Keyboard.press(TECLA_ALT_DERECHO);
Keyboard.press(TECLA_SHIFT_DERECHO);
Keyboard.press('J');
Keyboard.releaseAll();
}
if (boton_pulsado == 'h' && botones.getState() == PRESSED && capa_teclado == 1) {
Keyboard.press(TECLA_CTRL_IZQUIERDO);
Keyboard.press(TECLA_ALT_DERECHO);
Keyboard.press(TECLA_SHIFT_DERECHO);
Keyboard.press('K');
Keyboard.releaseAll();
}
if (boton_pulsado == 'i' && botones.getState() == PRESSED && capa_teclado == 1) {
Keyboard.press(TECLA_CTRL_IZQUIERDO);
Keyboard.press(TECLA_ALT_DERECHO);
Keyboard.press(TECLA_SHIFT_DERECHO);
Keyboard.press('L');
Keyboard.releaseAll();
}
// CAPA AZUL
if (boton_pulsado == 'a' && botones.getState() == PRESSED && capa_teclado == 2) {
Keyboard.press(TECLA_CTRL_IZQUIERDO);
Keyboard.press(TECLA_ALT_DERECHO);
Keyboard.press(TECLA_SHIFT_DERECHO);
Keyboard.press('Z');
Keyboard.releaseAll();
}
if (boton_pulsado == 'b' && botones.getState() == PRESSED && capa_teclado == 2) {
Keyboard.press(TECLA_CTRL_IZQUIERDO);
Keyboard.press(TECLA_ALT_DERECHO);
Keyboard.press(TECLA_SHIFT_DERECHO);
Keyboard.press('X');
Keyboard.releaseAll();
}
if (boton_pulsado == 'c' && botones.getState() == PRESSED && capa_teclado == 2) {
Keyboard.press(TECLA_CTRL_IZQUIERDO);
Keyboard.press(TECLA_ALT_DERECHO);
Keyboard.press(TECLA_SHIFT_DERECHO);
Keyboard.press('C');
Keyboard.releaseAll();
}
if (boton_pulsado == 'd' && botones.getState() == PRESSED && capa_teclado == 2) {
Keyboard.press(TECLA_CTRL_IZQUIERDO);
Keyboard.press(TECLA_ALT_DERECHO);
Keyboard.press(TECLA_SHIFT_DERECHO);
Keyboard.press('V');
Keyboard.releaseAll();
}
if (boton_pulsado == 'e' && botones.getState() == PRESSED && capa_teclado == 2) {
Keyboard.press(TECLA_CTRL_IZQUIERDO);
Keyboard.press(TECLA_ALT_DERECHO);
Keyboard.press(TECLA_SHIFT_DERECHO);
Keyboard.press('B');
Keyboard.releaseAll();
}
if (boton_pulsado == 'f' && botones.getState() == PRESSED && capa_teclado == 2) {
Keyboard.press(TECLA_CTRL_IZQUIERDO);
Keyboard.press(TECLA_ALT_DERECHO);
Keyboard.press(TECLA_SHIFT_DERECHO);
Keyboard.press('N');
Keyboard.releaseAll();
}
if (boton_pulsado == 'g' && botones.getState() == PRESSED && capa_teclado == 2) {
Keyboard.press(TECLA_CTRL_IZQUIERDO);
Keyboard.press(TECLA_ALT_DERECHO);
Keyboard.press(TECLA_SHIFT_DERECHO);
Keyboard.press('M');
Keyboard.releaseAll();
}
if (boton_pulsado == 'h' && botones.getState() == PRESSED && capa_teclado == 2) {
Keyboard.press(TECLA_CTRL_IZQUIERDO);
Keyboard.press(TECLA_ALT_DERECHO);
Keyboard.press(TECLA_SHIFT_DERECHO);
Keyboard.press('P');
Keyboard.releaseAll();
}
if (boton_pulsado == 'i' && botones.getState() == PRESSED && capa_teclado == 2) {
Keyboard.press(TECLA_CTRL_IZQUIERDO);
Keyboard.press(TECLA_ALT_DERECHO);
Keyboard.press(TECLA_SHIFT_DERECHO);
Keyboard.press('-');
Keyboard.releaseAll();
}
}