-
Notifications
You must be signed in to change notification settings - Fork 0
/
Midi_Controller_UNO.ino
183 lines (137 loc) · 4.07 KB
/
Midi_Controller_UNO.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#include <MIDI.h> // FortySevenEffects MIDI Library.
#define input 0
MIDI_CREATE_DEFAULT_INSTANC();
bool b_1_old = HIGH;
bool b_2_old = HIGH;
bool b_3_old = HIGH;
bool b_4_old = HIGH;
bool b_5_old = HIGH;
bool b_6_old = HIGH;
bool b_7_old = HIGH;
bool b_8_old = HIGH;
bool b_1_new;
bool b_2_new;
bool b_3_new;
bool b_4_new;
bool b_5_new;
bool b_6_new;
bool b_7_new;
bool b_8_new;
// Potentiometers
int pot_cc[] = {0,1,56,57,58,59,60,61,62,63,64,65,67,68,69,70};// MIDI CC values for the 16 potentiometers.
int pot_old_value[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int pot_new_value[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
void setup() {
// Pin Modes
pinMode(8, OUTPUT);// Multiplexer's address: Bit 0
pinMode(9, OUTPUT);// Multiplexer's address: Bit 1
pinMode(10, OUTPUT);// Multiplexer's address: Bit 2
pinMode(11, OUTPUT);// Multiplexer's address: Bit 3
pinMode(2, INPUT_PULLUP);// Buttons
pinMode(4, INPUT_PULLUP);
pinMode(6, INPUT_PULLUP);
pinMode(12, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
pinMode(7, INPUT_PULLUP);
pinMode(13, INPUT_PULLUP);
MIDI.begin(); // *
}
void multiplexer_1() {
for (int i = 0; i < 16; i++){
digitalWrite(8, HIGH && (i & B00000001));
digitalWrite(9, HIGH && (i & B00000010));
digitalWrite(10, HIGH && (i & B00000100));
digitalWrite(11, HIGH && (i & B00001000));
pot_new_value[i] = analogRead(input);
if(pot_new_value[i] - pot_old_value[i] >= 10 || pot_old_value[i] - pot_new_value[i] >= 10){
pot_old_value[i] = pot_new_value[i];
pot_new_value[i] = (map(pot_new_value[i], 0, 1023, 0, 127));
pot_new_value[i] = (constrain(pot_new_value[i], 0, 127));
MIDI.sendControlChange(pot_cc[i], pot_new_value[i], 1);
}
}
}
void loop() {
multiplexer_1();
b_1_new = digitalRead(2);
b_2_new = digitalRead(4);
b_3_new = digitalRead(6);
b_4_new = digitalRead(12);
b_5_new = digitalRead(3);
b_6_new = digitalRead(5);
b_7_new = digitalRead(7);
b_8_new = digitalRead(13);
if(b_1_new != b_1_old){
if(b_1_old == LOW){
MIDI.sendNoteOn(60, 127, 1); // Note C5 On - Velocity Value: 127 - MIDI Channel: 1
}
else{
MIDI.sendNoteOff(60, 0, 1); // Note C5 Off - Velocity Value: 0 - MIDI Channel: 1
}
b_1_old = b_1_new;
}
if(b_2_new != b_2_old){
if(b_2_new == LOW){
MIDI.sendNoteOn(62, 127, 1);// Note D5 On - Velocity Value: 127 - MIDI Channel: 1
}
else{
MIDI.sendNoteOff(62, 0, 1);// Note D5 Off - Velocity Value: 0 - MIDI Channel: 1
}
b_2_old = b_2_new;
}
if(b_3_new != b_3_old){
if(b_3_new == LOW){
MIDI.sendNoteOn(64, 127, 1);// Note E5 On - Velocity Value: 127 - MIDI Channel: 1
}
else{
MIDI.sendNoteOff(64, 0, 1);// Note E5 Off - Velocity Value: 0 - MIDI Channel: 1
}
b_3_old = b_3_new;
}
if(b_4_new != b_4_old){
if(b_4_new == LOW){
MIDI.sendNoteOn(65, 127, 1);// Note F5 On - Velocity Value: 127 - MIDI Channel: 1
}
else{
MIDI.sendNoteOff(65, 0, 1);// Note F5 Off - Velocity Value: 0 - MIDI Channel: 1
}
b_4_old = b_4_new;
}
if(b_5_new != b_5_old){
if(b_5_new == LOW){
MIDI.sendNoteOn(67, 127, 1);// Note G5 On - Velocity Value: 127 - MIDI Channel: 1
}
else{
MIDI.sendNoteOff(67, 0, 1);// Note G5 Off - Velocity Value: 0 - MIDI Channel: 1
}
b_5_old = b_5_new;
}
if(b_6_new != b_6_old){
if(b_6_new == LOW){
MIDI.sendNoteOn(69, 127, 1);// Note A5 On - Velocity Value: 127 - MIDI Channel: 1
}
else{
MIDI.sendNoteOff(69, 0, 1);// Note A5 Off - Velocity Value: 0 - MIDI Channel: 1
}
b_6_old = b_6_new;
}
if(b_7_new != b_7_old){
if(b_7_new == LOW){
MIDI.sendNoteOn(71, 127, 1);// Note B5 On - Velocity Value: 127 - MIDI Channel: 1
}
else{
MIDI.sendNoteOff(71, 0, 1);// Note B5 Off - Velocity Value: 0 - MIDI Channel: 1
}
b_7_old = b_7_new;
}
if(b_8_new != b_8_old){
if(b_8_new == LOW){
MIDI.sendNoteOn(72, 127, 1);// Note C6 On - Velocity Value: 127 - MIDI Channel: 1
}
else{
MIDI.sendNoteOff(72, 0, 1);// Note C6 On - Velocity Value: 0 - MIDI Channel: 1
}
b_8_old = b_8_new;
}
}