I'm trying to replace this code with something that uses the Arduino MIDI library:
#include <SoftwareSerial.h>
#define rxPin 2
#define txPin 1
SoftwareSerial midiSerial (rxPin,txPin);
void setup() {
midiSerial.begin(31250); }
while ( midiSerial.available()) {
incomingCommand = midiSerial.read();
incomingNote = midiSerial.read();
incomingVelocity = midiSerial.read()*8.05511811024;
if (incomingVelocity <=1023) {
midiSerial.write(incomingCommand);
midiSerial.write(incomingNote);
midiSerial.write(incomingVelocity); } }
Here's what I came up with:
#include <MIDI.h> // MIDI Output
MIDI_CREATE_DEFAULT_INSTANCE();
byte MIDIChannel;
byte programByte1;
byte controlByte1;
byte controlByte2;
void setup() {
MIDI.begin();
}
void loop() {
if (MIDI.read()) switch (MIDI.getType()) {
MIDIChannel = MIDI.getChannel();
case midi::ProgramChange:
programByte1 = MIDI.getData1();
break;
case midi::ControlChange:
controlByte1 = MIDI.getData1();
controlByte2 = MIDI.getData2();
break;
default: break;
}
}
Does that look correct? It doesn't function as smoothly as the version that uses SoftwareSerial