-
Notifications
You must be signed in to change notification settings - Fork 0
/
buttonbox.ino
167 lines (149 loc) · 4.87 KB
/
buttonbox.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
/*******************************************************************
* A simple Macro keyboard built with Arduino Pro Micro
* https://learn.sparkfun.com/tutorials/pro-micro--fio-v3-hookup-guide/hardware-overview-pro-micro
*
* MIT License
*
* Copyright (c) 2020 Eric B Dalquist
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*******************************************************************/
// https://github.com/NicoHood/HID
#include <HID-Project.h>
#include <HID-Settings.h>
// https://github.com/mprograms/SimpleRotary/blob/master/src/SimpleRotary.h
#include <SimpleRotary.h>
// https://github.com/bxparks/AceButton
#include <AceButton.h>
using namespace ace_button;
// Button Pinout
const int RED_PIN = 4;
const int BLUE_PIN = 3;
const int GREEN_PIN = 5;
const int YELLOW_PIN = 2;
const int BLACK_PIN = 6;
// ProMicro onboard LED pin (RXLED)
const int LED_PIN = 17;
// Create AceButton wrappers
AceButton redButton(RED_PIN);
AceButton blueButton(BLUE_PIN);
AceButton greenButton(GREEN_PIN);
AceButton yellowButton(YELLOW_PIN);
AceButton blackButton(BLACK_PIN);
// Create Rotary Switch wrapper
const int ROATARY_A_PIN = 20; // A2
const int ROATARY_B_PIN = 21; // A3
const int ROATARY_S_PIN = 19; // A1
SimpleRotary rotary(ROATARY_A_PIN, ROATARY_B_PIN, ROATARY_S_PIN);
// AceButton event handler
void handleEvent(AceButton*, uint8_t, uint8_t);
void setup() {
Serial.begin(9600);
// initialize the LED pin as an output:
pinMode(LED_PIN, OUTPUT);
// initialize the pushbutton pins as an input with onboard pullup:
pinMode(RED_PIN, INPUT_PULLUP);
pinMode(BLUE_PIN, INPUT_PULLUP);
pinMode(GREEN_PIN, INPUT_PULLUP);
pinMode(YELLOW_PIN, INPUT_PULLUP);
pinMode(BLACK_PIN, INPUT_PULLUP);
// init the event handlers
redButton.setEventHandler(handleEvent);
blueButton.setEventHandler(handleEvent);
greenButton.setEventHandler(handleEvent);
yellowButton.setEventHandler(handleEvent);
blackButton.setEventHandler(handleEvent);
// init media key support
Consumer.begin();
}
void loop() {
redButton.check();
blueButton.check();
greenButton.check();
yellowButton.check();
blackButton.check();
switch (rotary.rotate()) {
case 1: {
Serial.println("CW - Volume Up");
Consumer.write(MEDIA_VOLUME_UP);
break;
}
case 2: {
Serial.println("CCW - Volume Down");
Consumer.write(MEDIA_VOLUME_DOWN);
break;
}
}
if (rotary.push() == 1) {
Serial.println("Pushed");
Consumer.write(MEDIA_VOLUME_MUTE);
}
}
void handleEvent(AceButton* button, uint8_t eventType, uint8_t buttonState) {
if (eventType == AceButton::kEventPressed) {
switch (button->getPin()) {
case RED_PIN: {
Serial.println("RED: Blur");
Keyboard.press(KEY_LEFT_CTRL);
Keyboard.press(KEY_LEFT_SHIFT);
Keyboard.press(KEY_P);
delay(100);
Keyboard.releaseAll();
break;
}
case BLUE_PIN: {
Serial.println("BLUE: Camera");
Keyboard.press(KEY_LEFT_CTRL);
Keyboard.press(KEY_LEFT_SHIFT);
Keyboard.press(KEY_O);
delay(100);
Keyboard.releaseAll();
break;
}
case GREEN_PIN: {
Serial.println("GREEN: Hand");
Keyboard.press(KEY_LEFT_CTRL);
Keyboard.press(KEY_LEFT_SHIFT);
Keyboard.press(KEY_K);
delay(100);
Keyboard.releaseAll();
break;
}
case YELLOW_PIN: {
Serial.println("YELLOW: Mute");
Keyboard.press(KEY_LEFT_CTRL);
Keyboard.press(KEY_LEFT_SHIFT);
Keyboard.press(KEY_M);
delay(100);
Keyboard.releaseAll();
break;
}
case BLACK_PIN: {
Serial.println("BLACK: Password");
Keyboard.print("XXXXXXXXXX");
break;
}
}
} else {
Serial.println("Unknown Button: ");
Serial.println(button->getPin());
Serial.println(eventType);
Serial.println(buttonState);
}
}