|
| 1 | +/* |
| 2 | + * MIDIUSB_test.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 | +} |
| 30 | + |
| 31 | +// First parameter is the event type (0x0B = control change). |
| 32 | +// Second parameter is the event type, combined with the channel. |
| 33 | +// Third parameter is the control number number (0-119). |
| 34 | +// Fourth parameter is the control value (0-127). |
| 35 | + |
| 36 | +void controlChange(byte channel, byte control, byte value) { |
| 37 | + midiEventPacket_t event = {0x0B, 0xB0 | channel, control, value}; |
| 38 | + MidiUSB.sendMIDI(event); |
| 39 | +} |
| 40 | + |
| 41 | +void loop() { |
| 42 | + MidiUSB.accept(); |
| 43 | + delayMicroseconds(1); |
| 44 | + midiEventPacket_t rx; |
| 45 | + do { |
| 46 | + rx = MidiUSB.read(); |
| 47 | + if (rx.header != 0) { |
| 48 | + Serial.print("Received: "); |
| 49 | + Serial.print(rx.header, HEX); |
| 50 | + Serial.print("-"); |
| 51 | + Serial.print(rx.byte1, HEX); |
| 52 | + Serial.print("-"); |
| 53 | + Serial.print(rx.byte2, HEX); |
| 54 | + Serial.print("-"); |
| 55 | + Serial.println(rx.byte3, HEX); |
| 56 | + } |
| 57 | + } while (rx.header != 0); |
| 58 | +} |
0 commit comments