doc: Update example
This commit is contained in:
parent
47ce2acc16
commit
ce57d26d2c
|
|
@ -1,34 +1,36 @@
|
||||||
#include <MIDI.h>
|
#include <MIDI.h>
|
||||||
|
|
||||||
// Simple tutorial on how to receive and send MIDI messages.
|
// Simple tutorial on how to receive and send MIDI messages
|
||||||
|
// on a different serial port, using SoftwareSerial.
|
||||||
// Here, when receiving any message on channel 4, the Arduino
|
// Here, when receiving any message on channel 4, the Arduino
|
||||||
// will blink a led and play back a note for 1 second.
|
// will blink a led and play back a note for 1 second.
|
||||||
|
|
||||||
#if defined(ARDUINO_SAM_DUE) || defined(SAMD_SERIES)
|
#if defined(ARDUINO_SAM_DUE) || defined(SAMD_SERIES)
|
||||||
/* example not relevant for this hardware */
|
/* example not relevant for this hardware (SoftwareSerial not supported) */
|
||||||
MIDI_CREATE_DEFAULT_INSTANCE();
|
MIDI_CREATE_DEFAULT_INSTANCE();
|
||||||
#else
|
#else
|
||||||
#include <SoftwareSerial.h>
|
#include <SoftwareSerial.h>
|
||||||
|
using Transport = MIDI_NAMESPACE::SerialMIDI<SoftwareSerial>;
|
||||||
int rxPin = 18;
|
int rxPin = 18;
|
||||||
int txPin = 19;
|
int txPin = 19;
|
||||||
SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);
|
SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);
|
||||||
MIDI_NAMESPACE::SerialMIDI<SoftwareSerial> serialMIDI(mySerial);
|
Transport serialMIDI(mySerial);
|
||||||
MIDI_NAMESPACE::MidiInterface<MIDI_NAMESPACE::SerialMIDI<SoftwareSerial>> MIDI((MIDI_NAMESPACE::SerialMIDI<SoftwareSerial>&)serialMIDI);
|
MIDI_NAMESPACE::MidiInterface<Transport> MIDI((Transport&)serialMIDI);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
pinMode(LED_BUILTIN, OUTPUT);
|
pinMode(LED_BUILTIN, OUTPUT);
|
||||||
MIDI.begin(4); // Launch MIDI and listen to channel 4
|
MIDI.begin(4); // Launch MIDI and listen to channel 4
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
if (MIDI.read()) // If we have received a message
|
if (MIDI.read()) // If we have received a message
|
||||||
{
|
{
|
||||||
digitalWrite(LED_BUILTIN, HIGH);
|
digitalWrite(LED_BUILTIN, HIGH);
|
||||||
MIDI.sendNoteOn(42, 127, 1); // Send a Note (pitch 42, velo 127 on channel 1)
|
MIDI.sendNoteOn(42, 127, 1); // Send a Note (pitch 42, velo 127 on channel 1)
|
||||||
delay(1000); // Wait for a second
|
delay(1000); // Wait for a second
|
||||||
MIDI.sendNoteOff(42, 0, 1); // Stop the note
|
MIDI.sendNoteOff(42, 0, 1); // Stop the note
|
||||||
digitalWrite(LED_BUILTIN, LOW);
|
digitalWrite(LED_BUILTIN, LOW);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue