forked from charliewilliams/Arduino-Viscount-Bass-Pedals
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MIDITest.ino
79 lines (57 loc) · 1.4 KB
/
MIDITest.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
const int channel = 1;
const int note = 64;
const int velocity = 100;
const int durationMillis = 500;
static boolean onUSB = true;
static boolean testNoteIsOn = false;
static int lastEventMillis = 0;
// Alernates sending a note to usb & midi interface.
// The notes are a half-step apart
void midiTest() {
if (millis() - lastEventMillis > durationMillis) {
lastEventMillis = millis();
testNoteIsOn = !testNoteIsOn;
if (testNoteIsOn) {
if (onUSB) {
midiTestUSB(true);
} else {
midiTestInterface(true);
}
} else {
if (onUSB) {
midiTestUSB(false);
} else {
midiTestInterface(false);
}
onUSB = !onUSB;
}
}
}
void midiTestUSB(boolean turnOn) {
// while (usbMIDI.read()) {};
//
// if (turnOn) {
//
// Serial.println("NoteOn USB");
// usbMIDI.sendNoteOn(note, velocity, channel);
// digitalWrite(board_led, HIGH);
//
// } else {
//
// Serial.println("NoteOff USB");
// usbMIDI.sendNoteOff(note, velocity, channel);
// digitalWrite(board_led, LOW);
// }
}
void midiTestInterface(boolean turnOn) {
while (MIDI.read()) {};
if (turnOn) {
Serial.println("NoteOn MIDI");
MIDI.sendNoteOn(note + 1, velocity, channel);
digitalWrite(board_led, HIGH);
} else {
Serial.println("NoteOff MIDI");
MIDI.sendNoteOff(note + 1, velocity, channel);
digitalWrite(board_led, LOW);
}
}