-
Notifications
You must be signed in to change notification settings - Fork 0
/
loopercontrol_v1.2.ino
103 lines (85 loc) · 2.4 KB
/
loopercontrol_v1.2.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
#include <elapsedMillis.h>
#include <Bounce2.h>
#include <MIDI.h>
MIDI_CREATE_DEFAULT_INSTANCE();
const int channel = 11;
Bounce button1 = Bounce(2, 5); // 5 = 5 ms debounce time
Bounce button2 = Bounce(3, 5); // which is appropriate for good
Bounce button3 = Bounce(4, 5); // quality mechanical pushbuttons
Bounce button4 = Bounce(5, 5);
Bounce button5 = Bounce(6, 5);
Bounce button6 = Bounce(7, 5);
Bounce button7 = Bounce(8, 5);
const int controllerA1 = 110;
void setup() {
Serial.begin(31250);
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
pinMode(6, INPUT_PULLUP);
pinMode(7, INPUT_PULLUP);
pinMode(8, INPUT_PULLUP);
}
int previousA1 = -1;
elapsedMillis msec = 0;
void loop() {
button1.update();
button2.update();
button3.update();
button4.update();
button5.update();
button6.update();
button7.update();
if (button1.fallingEdge()) {
MIDI.sendControlChange(101, 127, channel); // CC=101
}
if (button2.fallingEdge()) {
MIDI.sendControlChange(102, 127, channel); // CC=102
}
if (button3.fallingEdge()) {
MIDI.sendControlChange(103, 127, channel); // CC=103
}
if (button4.fallingEdge()) {
MIDI.sendControlChange(104, 127, channel); // CC=104
}
if (button5.fallingEdge()) {
MIDI.sendControlChange(105, 127, channel); // CC=105
}
if (button6.fallingEdge()) {
MIDI.sendControlChange(106, 127, channel); // CC=106
}
if (button7.fallingEdge()) {
MIDI.sendControlChange(107, 127, channel); // CC=107
}
if (button1.risingEdge()) {
MIDI.sendControlChange(101, 0, channel); // CC=101
}
if (button2.risingEdge()) {
MIDI.sendControlChange(102, 0, channel); // CC=102
}
if (button3.risingEdge()) {
MIDI.sendControlChange(103, 0, channel); // CC=103
}
if (button4.risingEdge()) {
MIDI.sendControlChange(104, 0, channel); // CC=104
}
if (button5.risingEdge()) {
MIDI.sendControlChange(105, 0, channel); // CC=105
}
if (button6.risingEdge()) {
MIDI.sendControlChange(106, 0, channel); // CC=106
}
if (button7.risingEdge()) {
MIDI.sendControlChange(107, 0, channel); // CC=107
}
if (msec >= 20) {
msec = 0;
int n1 = analogRead(A0) / 8;
// only transmit MIDI messages if analog input changed
if (abs(n1 - previousA1)>1) {
MIDI.sendControlChange(controllerA1, n1, channel);
previousA1 = n1;
}
}
}