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