forked from charliewilliams/Arduino-Viscount-Bass-Pedals
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathControl.ino
61 lines (48 loc) · 1.86 KB
/
Control.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
#include <AnalogMultiButton.h>
const int BUTTONS_PIN = A0; //14;
const int BUTTONS_TOTAL = 4;
// find out what the value of analogRead is when you press each of your buttons and put them in this array
// you can find this out by putting Serial.println(analogRead(BUTTONS_PIN)); in your loop() and opening the serial monitor to see the values
// make sure they are in order of smallest to largest
const int BUTTONS_VALUES[BUTTONS_TOTAL] = {0, 277, 437, 540};
// you can also define constants for each of your buttons, which makes your code easier to read
// define these in the same order as the numbers in your BUTTONS_VALUES array, so whichever button has the smallest analogRead() number should come first
const int OCTAVE_DOWN_BTN = 0;
const int OCTAVE_UP_BTN = 1;
const int ARROW_DOWN = 2;
const int ARROW_UP = 3;
// make an AnalogMultiButton object, pass in the pin, total and values array
AnalogMultiButton buttons(BUTTONS_PIN, BUTTONS_TOTAL, BUTTONS_VALUES);
// pass a fourth parameter to set the debounce time in milliseconds
// this defaults to 20 and can be increased if you're working with particularly bouncy buttons
int lastMillis = 0;
void setupControls() {
pinMode(BUTTONS_PIN, INPUT);
}
void updateControls() {
/* DIAGNOSTIC */
// if (millis() - lastMillis > 100) {
// lastMillis = millis();
// Serial.println(analogRead(BUTTONS_PIN));
// }
// return;
buttons.update();
if (buttons.onPress(OCTAVE_DOWN_BTN)) {
Serial.println("Octave DOWN");
octave--;
}
else if (buttons.onPress(OCTAVE_UP_BTN)) {
Serial.println("Octave UP");
octave++;
}
else if (buttons.onPress(ARROW_UP)) {
Serial.println("UP arrow");
Keyboard.press(KEY_UP_ARROW);
Keyboard.release(KEY_UP_ARROW);
}
else if (buttons.onPress(ARROW_DOWN)) {
Serial.println("DOWN arrow");
Keyboard.press(KEY_DOWN_ARROW);
Keyboard.release(KEY_DOWN_ARROW);
}
}