-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirmware_rev2.ino
73 lines (63 loc) · 1.42 KB
/
firmware_rev2.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
#include <Keyboard.h>
// CONFIG
// Set button mapping here
const int BUTTONS[3] = {3,4,5};
const int KEYS[3] = {KEY_LEFT_CTRL, KEY_LEFT_ALT, KEY_LEFT_SHIFT};
// Set base polarity here for each pedal.
// Inverted pedals send 5V when open, 0V when closed.
// For pedals compatible with Yamaha keyboards, set to `true`.
// By default, leave to false.
const bool INVERTED[3] = {false,false,false};
// FIRMWARE
int buttonStates[3] = {0,0,0};
bool keyboardStates[3] = {false, false, false};
void incrementState(int i) {
if (buttonStates[i] < 1) {
buttonStates[i]++;
}
}
void decrementState(int i) {
if (buttonStates[i] > 0) {
buttonStates[i]--;
}
}
void readButton(int i) {
if (digitalRead(BUTTONS[i]) == HIGH) {
if (INVERTED[i]) {
decrementState(i);
} else {
incrementState(i);
}
} else {
if (INVERTED[i]) {
incrementState(i);
}
else {
decrementState(i);
}
}
}
void updateKeyboard() {
for (int i = 0; i < 3; i++) {
if (buttonStates[i] > 0 && !keyboardStates[i]) {
keyboardStates[i] = true;
Keyboard.press(KEYS[i]);
} else if (buttonStates[i] < 1 && keyboardStates[i]) {
keyboardStates[i] = false;
Keyboard.release(KEYS[i]);
}
}
}
void setup() {
Keyboard.begin();
for (int i = 0; i < 3; i++) {
pinMode(BUTTONS[i],INPUT);
}
}
void loop() {
for (int i = 0; i < 3; i++) {
readButton(i);
}
updateKeyboard();
delay(5);
}