Skip to content

Commit ce57d26

Browse files
committed
doc: Update example
1 parent 47ce2ac commit ce57d26

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

examples/AltPinSerial/AltPinSerial.ino

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,36 @@
11
#include <MIDI.h>
22

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.
45
// Here, when receiving any message on channel 4, the Arduino
56
// will blink a led and play back a note for 1 second.
67

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) */
910
MIDI_CREATE_DEFAULT_INSTANCE();
1011
#else
1112
#include <SoftwareSerial.h>
13+
using Transport = MIDI_NAMESPACE::SerialMIDI<SoftwareSerial>;
1214
int rxPin = 18;
1315
int txPin = 19;
1416
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);
1719
#endif
1820

1921
void setup()
2022
{
2123
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
2325
}
2426

2527
void loop()
2628
{
27-
if (MIDI.read()) // If we have received a message
29+
if (MIDI.read()) // If we have received a message
2830
{
2931
digitalWrite(LED_BUILTIN, HIGH);
3032
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
3234
MIDI.sendNoteOff(42, 0, 1); // Stop the note
3335
digitalWrite(LED_BUILTIN, LOW);
3436
}

0 commit comments

Comments
 (0)