|
1 | 1 | #include <MIDI.h> |
2 | 2 |
|
3 | | -// Simple tutorial on how to receive and send MIDI messages. |
| 3 | +// Simple tutorial on how to receive and send MIDI messages |
| 4 | +// on a different serial port, using SoftwareSerial. |
4 | 5 | // Here, when receiving any message on channel 4, the Arduino |
5 | 6 | // will blink a led and play back a note for 1 second. |
6 | 7 |
|
7 | | -#if defined(ARDUINO_SAM_DUE) || defined(SAMD_SERIES) |
8 | | - /* example not relevant for this hardware */ |
| 8 | +#if defined(ARDUINO_SAM_DUE) || defined(SAMD_SERIES) |
| 9 | + /* example not relevant for this hardware (SoftwareSerial not supported) */ |
9 | 10 | MIDI_CREATE_DEFAULT_INSTANCE(); |
10 | 11 | #else |
11 | 12 | #include <SoftwareSerial.h> |
| 13 | + using Transport = MIDI_NAMESPACE::SerialMIDI<SoftwareSerial>; |
12 | 14 | int rxPin = 18; |
13 | 15 | int txPin = 19; |
14 | 16 | SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin); |
15 | | - MIDI_NAMESPACE::SerialMIDI<SoftwareSerial> serialMIDI(mySerial); |
16 | | - MIDI_NAMESPACE::MidiInterface<MIDI_NAMESPACE::SerialMIDI<SoftwareSerial>> MIDI((MIDI_NAMESPACE::SerialMIDI<SoftwareSerial>&)serialMIDI); |
| 17 | + Transport serialMIDI(mySerial); |
| 18 | + MIDI_NAMESPACE::MidiInterface<Transport> MIDI((Transport&)serialMIDI); |
17 | 19 | #endif |
18 | 20 |
|
19 | 21 | void setup() |
20 | 22 | { |
21 | 23 | pinMode(LED_BUILTIN, OUTPUT); |
22 | | - MIDI.begin(4); // Launch MIDI and listen to channel 4 |
| 24 | + MIDI.begin(4); // Launch MIDI and listen to channel 4 |
23 | 25 | } |
24 | 26 |
|
25 | 27 | void loop() |
26 | 28 | { |
27 | | - if (MIDI.read()) // If we have received a message |
| 29 | + if (MIDI.read()) // If we have received a message |
28 | 30 | { |
29 | 31 | digitalWrite(LED_BUILTIN, HIGH); |
30 | 32 | MIDI.sendNoteOn(42, 127, 1); // Send a Note (pitch 42, velo 127 on channel 1) |
31 | | - delay(1000); // Wait for a second |
| 33 | + delay(1000); // Wait for a second |
32 | 34 | MIDI.sendNoteOff(42, 0, 1); // Stop the note |
33 | 35 | digitalWrite(LED_BUILTIN, LOW); |
34 | 36 | } |
|
0 commit comments