forked from charliewilliams/Arduino-Viscount-Bass-Pedals
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MIDI.ino
66 lines (48 loc) · 1.44 KB
/
MIDI.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
static int intensity = 64;
const static long debounceDelay = 50; // the debounce time; increase if the output flickers
uint16_t pressedPedals = 0x00;
uint16_t previousPedals = 0x00;
uint16_t debounceTimes = 0x00;
void midiTick() {
readPedals();
readIntensity();
playNotes();
}
void readPedals() {
for (int i = 0; i < NUM_KEYS; i++) {
if (digitalRead(i) == HIGH) {
bitWrite(pressedPedals, i, 1);
delay(50);
}
else {
bitWrite(pressedPedals, i, 0);
}
}
}
// TODO future expansion
void readIntensity() {
// int val = analogRead(intensityPot);
// intensity = (uint8_t) (map(val, 0, 1023, 0, 127));
}
void playNotes() {
for (int i = 0; i < NUM_KEYS; i++) {
if (bitRead(pressedPedals, i) != bitRead(previousPedals, i)) {
int pedal = notePitches[i];
int note = notePitches[i] + octave * 12;
if (bitRead(pressedPedals, i)) {
bitWrite(previousPedals, i , 1);
usbMIDI.sendNoteOn(note, intensity, 1);
MIDI.sendNoteOn(note, intensity, 0);
Serial.print("Note on: "); Serial.print(pedal); Serial.print(" / "); Serial.println(note);
writeLED(i, true);
}
else {
bitWrite(previousPedals, i , 0);
usbMIDI.sendNoteOff(note, intensity, 1);
MIDI.sendNoteOff(note, intensity, 0);
Serial.print("Note off: "); Serial.print(pedal); Serial.print(" / "); Serial.println(note);
writeLED(i, false);
}
}
}
}