Skip to content

added CustomBaudRate example #262

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/platformio.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
- Input
- RPN_NRPN
- SimpleSynth
- CustomBaudRate
board:
- uno
- due
Expand Down
12 changes: 6 additions & 6 deletions doc/midi_DoxygenMainPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// Examples

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

/*!
\example MIDI_Callbacks.ino
\example Callbacks.ino
This example shows how to use callbacks for easier MIDI input handling. \n
*/

/*!
\example MIDI_Bench.ino
\example MIDI_DualMerger.ino
\example MIDI_Input.ino
\example MIDI_SimpleSynth.ino
\example Bench.ino
\example DualMerger.ino
\example Input.ino
\example SimpleSynth.ino
*/

// -----------------------------------------------------------------------------
Expand Down
31 changes: 31 additions & 0 deletions examples/CustomBaudRate/CustomBaudRate.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <MIDI.h>

// Override the default MIDI baudrate to
// a decoding program such as Hairless MIDI (set baudrate to 115200)

struct CustomBaudRate : public MIDI_NAMESPACE::DefaultSettings {
static const long BaudRate = 115200;
};

#if defined(ARDUINO_SAM_DUE) || defined(USBCON) || defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MKL26Z64__)
// Leonardo, Due and other USB boards use Serial1 by default.
MIDI_CREATE_CUSTOM_INSTANCE(HardwareSerial, Serial1, MIDI, CustomBaudRate);
#else
MIDI_CREATE_CUSTOM_INSTANCE(HardwareSerial, Serial, MIDI, CustomBaudRate);
#endif

void setup() {
pinMode(LED_BUILTIN, OUTPUT);
MIDI.begin(MIDI_CHANNEL_OMNI);
}

void loop() {
if (MIDI.read()) // If we have received a message
{
digitalWrite(LED_BUILTIN, HIGH);
MIDI.sendNoteOn(42, 127, 1); // Send a Note (pitch 42, velo 127 on channel 1)
delay(1000); // Wait for a second
MIDI.sendNoteOff(42, 0, 1); // Stop the note
digitalWrite(LED_BUILTIN, LOW);
}
}