-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch_deck_arduino.ino
264 lines (231 loc) · 6.11 KB
/
sketch_deck_arduino.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
#include "HID-Project.h"
#include "RotaryEncoder.h"
#define DEBOUNCE 60 // Tempo de debounce para os botões
#define VOLUME // Definindo recurso volume (encoder)
#define OBSBTNS // Definindo os atalhos do OBS (botões)
#define WINBTNS // Definindo os atalhos do Windows (botões)
#ifdef VOLUME // Pinagem do encoder ... (Nome pino e Pino)
#define S_ONE 5 // S1
#define S_TWO 6 // S2
#define KEY 7 // Botão tactil do encoder
RotaryEncoder encoder(S_ONE, S_TWO);
#endif
#ifdef OBSBTNS // Pinagem dos botões que vão ser utilizados para atalhos do OBS ... (Nome Botão e Pino)
#define BTN1 2 // Botão BTN1 no pin 2
#define BTN2 3 // Botão BTN2 no pin 3
#define BTN3 4 // Botão BTN3 no pin 4
#define SIZEOBSBTNS 3 // Quantidade de botões que foi declarado em cima (ATUALIZAR CASO VOCE ALTERE)
int btnsOBS[SIZEOBSBTNS] = {BTN1, BTN2, BTN3}; // Nome dos botões que foi declarado em cima (ATUALIZAR CASO VOCE ALTERE)
unsigned long timeOBSBTNS[SIZEOBSBTNS];
bool pressOBS[SIZEOBSBTNS];
#endif
#ifdef WINBTNS // Pinagem dos botões que vão ser utilizados para atalhos do WINDOWS ... (Nome Botão e Pino)
#define BTN4 8 // Botão BTN8 no pin 8
#define BTN5 9 // Botão BTN9 no pin 9
#define BTN6 10 // Botão BTN10 no pin 10
#define BTN7 11 // Botão BTN11 no pin 11
#define BTN8 12 // Botão BTN11 no pin 12
#define SIZEWINBTNS 5 // Quantidade de botões que foi declarado em cima (ATUALIZAR CASO VOCE ALTERE)
int btnsWIN[SIZEWINBTNS] = {BTN4, BTN5, BTN6, BTN7, BTN8}; // Nome dos botões que foi declarado em cima (ATUALIZAR CASO VOCE ALTERE)
unsigned long timeWINBTNS[SIZEWINBTNS];
bool pressWIN[SIZEWINBTNS];
#endif
bool buttonPressed(byte PinButton); // Escopo da função
void setup()
{
Consumer.begin();
BootKeyboard.begin();
#ifdef VOLUME
pinMode(S_ONE, INPUT_PULLUP);
pinMode(S_TWO, INPUT_PULLUP);
pinMode(KEY, INPUT_PULLUP);
#endif
#ifdef OBSBTNS
int i;
for (i = 0; i < SIZEOBSBTNS; i++)
{
pinMode(btnsOBS[i], INPUT_PULLUP);
timeOBSBTNS[i] = 0;
pressOBS[i] = false;
}
#endif
#ifdef WINBTNS
int j;
for (j = 0; j < SIZEWINBTNS; j++)
{
pinMode(btnsWIN[j], INPUT_PULLUP);
timeWINBTNS[j] = 0;
pressWIN[j] = false;
}
#endif
}
void loop()
{
#ifdef VOLUME
static int pos = 0;
encoder.tick();
int newPos = encoder.getPosition();
if (pos != newPos)
{
if (newPos > pos)
{
Consumer.write(MEDIA_VOL_UP); // Aumentar volume (encoder)
}
else
{
Consumer.write(MEDIA_VOL_DOWN); // Diminuir volume (encoder)
}
pos = newPos;
}
if (buttonPressed(KEY))
{
Consumer.write(MEDIA_PLAY_PAUSE); // Tocar/Pausar (botão tactil encoder)
}
#endif
#ifdef OBSBTNS
int i;
for (i = 0; i < SIZEOBSBTNS; i++)
{
if (digitalRead(btnsOBS[i]))
{
if (timeOBSBTNS[i] == 0)
{
timeOBSBTNS[i] = millis();
}
else
{
if ((millis() - timeOBSBTNS[i]) > DEBOUNCE && !pressOBS[i])
{
pressOBS[i] = true;
switch (i)
{
case 0: // Atalho para mudar de Cena OBS
{
BootKeyboard.press(KEY_LEFT_CTRL);
BootKeyboard.press(KEY_LEFT_ALT);
BootKeyboard.press(KEY_LEFT_SHIFT);
BootKeyboard.write(KEY_A);
BootKeyboard.releaseAll();
break;
}
case 1: // Atalho para mutar OBS
{
BootKeyboard.press(KEY_LEFT_CTRL);
BootKeyboard.press(KEY_LEFT_ALT);
BootKeyboard.press(KEY_LEFT_SHIFT);
BootKeyboard.write(KEY_M);
BootKeyboard.releaseAll();
break;
}
case 2: // Atalho para desmutar OBS
{
BootKeyboard.press(KEY_LEFT_CTRL);
BootKeyboard.press(KEY_LEFT_ALT);
BootKeyboard.press(KEY_LEFT_SHIFT);
BootKeyboard.write(KEY_U);
BootKeyboard.releaseAll();
break;
}
default:
break;
}
}
}
}
else
{
if (timeOBSBTNS[i] != 0)
{
timeOBSBTNS[i] = 0;
pressOBS[i] = false;
}
}
}
#endif
#ifdef WINBTNS
int k;
for (k = 0; k < SIZEWINBTNS; k++)
{
if (digitalRead(btnsWIN[k]))
{
if (timeWINBTNS[k] == 0)
{
timeWINBTNS[k] = millis();
}
else
{
if ((millis() - timeWINBTNS[k]) > DEBOUNCE && !pressWIN[k])
{
pressWIN[k] = true;
switch (k)
{
case 0: // Abrir o aplicativo GITHUB DESKTOP
{
BootKeyboard.press(KEY_LEFT_CTRL);
BootKeyboard.press(KEY_LEFT_ALT);
BootKeyboard.press(KEY_LEFT_SHIFT);
BootKeyboard.write(KEY_G);
BootKeyboard.releaseAll();
break;
}
case 1: // Abrir o GERENCIADOR DE TAREFAS do WINDOWS
{
BootKeyboard.press(KEY_LEFT_CTRL);
BootKeyboard.press(KEY_LEFT_SHIFT);
BootKeyboard.write(KEY_ESC);
BootKeyboard.releaseAll();
break;
}
case 2: // Abrir uma nova janela em branco do seu navegador padrão
{
Consumer.write(CONSUMER_BROWSER_HOME);
break;
}
case 3: // Abrir Explorador de Arquivos (explorer) Windows
{
Consumer.write(CONSUMER_EXPLORER);
break;
}
case 4: // Abrir a calculadora padrão do WINDOWS
{
Consumer.write(CONSUMER_CALCULATOR);
break;
}
default:
break;
}
}
}
}
else
{
if (timeWINBTNS[k] != 0)
{
timeWINBTNS[k] = 0;
pressWIN[k] = false;
}
}
}
#endif
}
bool buttonPressed(byte PinButton)
{
static unsigned long swDebounce;
bool SW = digitalRead(PinButton);
static bool swBefore = 1;
if (millis() - swDebounce > DEBOUNCE)
{
if (!SW && swBefore)
{
swDebounce = millis();
swBefore = SW;
return true;
}
else if (SW && !swBefore)
{
swDebounce = millis();
swBefore = SW;
}
}
return false;
}