Skip to content

Commit 7c0d716

Browse files
authored
added CustomBaudRate example (#262)
* added CustomBaudRate example - added customer baudrate example - fixed old refs to examples in Doxygen * fixed compile error for boards that have no Serial
1 parent 8f8c7cf commit 7c0d716

File tree

3 files changed

+38
-6
lines changed

3 files changed

+38
-6
lines changed

.github/workflows/platformio.yml

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ jobs:
2323
- Input
2424
- RPN_NRPN
2525
- SimpleSynth
26+
- CustomBaudRate
2627
board:
2728
- uno
2829
- due

doc/midi_DoxygenMainPage.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// Examples
1313

1414
/*!
15-
\example MIDI_Basic_IO.ino
15+
\example Basic_IO.ino
1616
This example shows how to perform simple input and output MIDI. \n
1717
\n
1818
When any message arrives to the Arduino, the LED is turned on,
@@ -29,15 +29,15 @@
2929
*/
3030

3131
/*!
32-
\example MIDI_Callbacks.ino
32+
\example Callbacks.ino
3333
This example shows how to use callbacks for easier MIDI input handling. \n
3434
*/
3535

3636
/*!
37-
\example MIDI_Bench.ino
38-
\example MIDI_DualMerger.ino
39-
\example MIDI_Input.ino
40-
\example MIDI_SimpleSynth.ino
37+
\example Bench.ino
38+
\example DualMerger.ino
39+
\example Input.ino
40+
\example SimpleSynth.ino
4141
*/
4242

4343
// -----------------------------------------------------------------------------
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include <MIDI.h>
2+
3+
// Override the default MIDI baudrate to
4+
// a decoding program such as Hairless MIDI (set baudrate to 115200)
5+
6+
struct CustomBaudRate : public MIDI_NAMESPACE::DefaultSettings {
7+
static const long BaudRate = 115200;
8+
};
9+
10+
#if defined(ARDUINO_SAM_DUE) || defined(USBCON) || defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MKL26Z64__)
11+
// Leonardo, Due and other USB boards use Serial1 by default.
12+
MIDI_CREATE_CUSTOM_INSTANCE(HardwareSerial, Serial1, MIDI, CustomBaudRate);
13+
#else
14+
MIDI_CREATE_CUSTOM_INSTANCE(HardwareSerial, Serial, MIDI, CustomBaudRate);
15+
#endif
16+
17+
void setup() {
18+
pinMode(LED_BUILTIN, OUTPUT);
19+
MIDI.begin(MIDI_CHANNEL_OMNI);
20+
}
21+
22+
void loop() {
23+
if (MIDI.read()) // If we have received a message
24+
{
25+
digitalWrite(LED_BUILTIN, HIGH);
26+
MIDI.sendNoteOn(42, 127, 1); // Send a Note (pitch 42, velo 127 on channel 1)
27+
delay(1000); // Wait for a second
28+
MIDI.sendNoteOff(42, 0, 1); // Stop the note
29+
digitalWrite(LED_BUILTIN, LOW);
30+
}
31+
}

0 commit comments

Comments
 (0)