1+ /*
2+ * MIDIUSB_loop.ino
3+ *
4+ * Created: 4/6/2015 10:47:08 AM
5+ * Author: gurbrinder grewal
6+ * Modified by Arduino LLC (2015)
7+ */
8+
9+ #include " MIDIUSB.h"
10+
11+ // First parameter is the event type (0x09 = note on, 0x08 = note off).
12+ // Second parameter is note-on/note-off, combined with the channel.
13+ // Channel can be anything between 0-15. Typically reported to the user as 1-16.
14+ // Third parameter is the note number (48 = middle C).
15+ // Fourth parameter is the velocity (64 = normal, 127 = fastest).
16+
17+ void noteOn (byte channel, byte pitch, byte velocity) {
18+ midiEventPacket_t noteOn = {0x09 , 0x90 | channel, pitch, velocity};
19+ MidiUSB.sendMIDI (noteOn);
20+ }
21+
22+ void noteOff (byte channel, byte pitch, byte velocity) {
23+ midiEventPacket_t noteOff = {0x08 , 0x80 | channel, pitch, velocity};
24+ MidiUSB.sendMIDI (noteOff);
25+ }
26+
27+ void setup () {
28+ Serial.begin (115200 );
29+ pinMode (LED_BUILTIN, OUTPUT);
30+ }
31+
32+ // First parameter is the event type (0x0B = control change).
33+ // Second parameter is the event type, combined with the channel.
34+ // Third parameter is the control number number (0-119).
35+ // Fourth parameter is the control value (0-127).
36+
37+ void controlChange (byte channel, byte control, byte value) {
38+ midiEventPacket_t event = {0x0B , 0xB0 | channel, control, value};
39+ MidiUSB.sendMIDI (event);
40+ }
41+
42+ void loop () {
43+ // MidiUSB.accept();
44+ // delayMicroseconds(1);
45+ midiEventPacket_t rx;
46+ do {
47+ rx = MidiUSB.read ();
48+ if (rx.header != 0 ) {
49+ // send back the received MIDI command
50+ MidiUSB.sendMIDI (rx);
51+ MidiUSB.flush ();
52+ }
53+ } while (rx.header != 0 );
54+ }
0 commit comments