-
Notifications
You must be signed in to change notification settings - Fork 0
/
hoykeysV2.ino
141 lines (110 loc) · 2.55 KB
/
hoykeysV2.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
#include "HID-Project.h"
#include <Rotary.h>
#define pinLed1 9
#define pinLed2 6
#define pinLed3 5
#define pinLed4 3
#define pinBtn1 8
#define pinBtn2 7
#define pinBtn3 4
#define pinBtn4 2
#define pinBtnRotary 21
Rotary r = Rotary(10,16);
unsigned long lastDebounceTimeBtn1 = 0;
unsigned long lastDebounceTimeBtn2 = 0;
unsigned long lastDebounceTimeBtn3 = 0;
unsigned long lastDebounceTimeBtn4 = 0;
unsigned long debounceDelay = 250;
void setup() {
//Serial.begin(9600);
pinMode(pinBtn1, INPUT_PULLUP);
pinMode(pinBtn2, INPUT_PULLUP);
pinMode(pinBtn3, INPUT_PULLUP);
pinMode(pinBtn4, INPUT_PULLUP);
pinMode(pinBtnRotary, INPUT);
pinMode(pinLed1,OUTPUT);
pinMode(pinLed2,OUTPUT);
pinMode(pinLed3,OUTPUT);
pinMode(pinLed4,OUTPUT);
todosEncendidos();
}
void loop() {
if(digitalRead(pinBtn1) == LOW) {
if((lastDebounceTimeBtn1 - millis()) > debounceDelay) {
lastDebounceTimeBtn1 = millis();
button1();
}
}
if(digitalRead(pinBtn2) == LOW) {
if((lastDebounceTimeBtn2 - millis()) > debounceDelay) {
lastDebounceTimeBtn2 = millis();
button2();
}
}
if(digitalRead(pinBtn3) == LOW) {
if((lastDebounceTimeBtn3 - millis()) > debounceDelay) {
lastDebounceTimeBtn3 = millis();
button3();
}
}
if(digitalRead(pinBtn4) == LOW) {
if((lastDebounceTimeBtn4 - millis()) > debounceDelay) {
lastDebounceTimeBtn4 = millis();
button4();
}
}
unsigned char result = r.process();
if (result == DIR_CW) {
girarDerecha();
} else if(result == DIR_CCW) {
girarIzquierda();
}
}
void todosEncendidos() {
digitalWrite(pinLed1, HIGH);
digitalWrite(pinLed2, HIGH);
digitalWrite(pinLed3, HIGH);
digitalWrite(pinLed4, HIGH);
}
void button1() {
Keyboard.begin();
Keyboard.println("Boton1");
delay(80);
Keyboard.releaseAll();
Keyboard.end();
}
void button4() {
Consumer.begin();
Consumer.write(MEDIA_VOLUME_UP);
delay(10);
Consumer.releaseAll();
Consumer.end();
}
void button2() {
Consumer.begin();
Consumer.write(MEDIA_VOLUME_DOWN);
delay(10);
Consumer.releaseAll();
Consumer.end();
}
void button3() {
Keyboard.begin();
Keyboard.println("Boton3");
delay(80);
Keyboard.releaseAll();
Keyboard.end();
}
void girarDerecha() {
Keyboard.begin();
Keyboard.println("Derecha");
delay(80);
Keyboard.releaseAll();
Keyboard.end();
}
void girarIzquierda() {
Keyboard.begin();
Keyboard.println("Izquierda");
delay(80);
Keyboard.releaseAll();
Keyboard.end();
}