Code:
void setup() {
Serial.begin(115200);
usbMIDI.setHandleNoteOff(myNoteOff);
usbMIDI.setHandleNoteOn(myNoteOn);
usbMIDI.setHandleAfterTouchPoly(myAfterTouchPoly);
usbMIDI.setHandleControlChange(myControlChange);
usbMIDI.setHandleProgramChange(myProgramChange);
usbMIDI.setHandleAfterTouchChannel(myAfterTouchChannel);
usbMIDI.setHandlePitchChange(myPitchChange);
usbMIDI.setHandleSystemExclusive(mySystemExclusiveChunk);
usbMIDI.setHandleSystemExclusive(mySystemExclusive);
usbMIDI.setHandleTimeCodeQuarterFrame(myTimeCodeQuarterFrame);
usbMIDI.setHandleSongPosition(mySongPosition);
usbMIDI.setHandleSongSelect(mySongSelect);
usbMIDI.setHandleTuneRequest(myTuneRequest);
usbMIDI.setHandleClock(myClock);
usbMIDI.setHandleStart(myStart);
usbMIDI.setHandleContinue(myContinue);
usbMIDI.setHandleStop(myStop);
usbMIDI.setHandleActiveSensing(myActiveSensing);
usbMIDI.setHandleSystemReset(mySystemReset);
usbMIDI.setHandleRealTimeSystem(myRealTimeSystem);
}
void loop() {
usbMIDI.read(); // USB MIDI receive
}
void myNoteOn(byte channel, byte note, byte velocity) {
Serial.print("Note On, ch=");
Serial.print(channel, DEC);
Serial.print(", note=");
Serial.print(note, DEC);
Serial.print(", velocity=");
Serial.print(velocity, DEC);
Serial.println();
}
void myNoteOff(byte channel, byte note, byte velocity) {
Serial.print("Note Off, ch=");
Serial.print(channel, DEC);
Serial.print(", note=");
Serial.print(note, DEC);
Serial.print(", velocity=");
Serial.print(velocity, DEC);
Serial.println();
}
void myAfterTouchPoly(byte channel, byte note, byte velocity) {
Serial.print("AfterTouch Change, ch=");
Serial.print(channel, DEC);
Serial.print(", note=");
Serial.print(note, DEC);
Serial.print(", velocity=");
Serial.print(velocity, DEC);
Serial.println();
}
void myControlChange(byte channel, byte control, byte value) {
Serial.print("Control Change, ch=");
Serial.print(channel, DEC);
Serial.print(", control=");
Serial.print(control, DEC);
Serial.print(", value=");
Serial.print(value, DEC);
Serial.println();
}
void myProgramChange(byte channel, byte program) {
Serial.print("Program Change, ch=");
Serial.print(channel, DEC);
Serial.print(", program=");
Serial.print(program, DEC);
Serial.println();
}
void myAfterTouchChannel(byte channel, byte pressure) {
Serial.print("After Touch, ch=");
Serial.print(channel, DEC);
Serial.print(", pressure=");
Serial.print(pressure, DEC);
Serial.println();
}
void myPitchChange(byte channel, int pitch) {
Serial.print("Pitch Change, ch=");
Serial.print(channel, DEC);
Serial.print(", pitch=");
Serial.print(pitch, DEC);
Serial.println();
}
void mySystemExclusiveChunk(const byte *data, uint16_t length, bool last) {
Serial.print("SysEx Message: ");
printBytes(data, length);
if (last) {
Serial.println(" (end)");
} else {
Serial.println(" (to be continued)");
}
}
void mySystemExclusive(byte *data, unsigned int length) {
Serial.print("SysEx Message: ");
printBytes(data, length);
Serial.println();
}
void myTimeCodeQuarterFrame(byte data) {
}
void mySongPosition(uint16_t beats) {
}
void mySongSelect(byte songNumber) {
}
void myTuneRequest() {
}
void myClock() {
}
void myStart() {
}
void myContinue() {
}
void myStop() {
}
void myActiveSensing() {
}
void mySystemReset() {
}
void myRealTimeSystem(uint8_t realtimebyte) {
}
void printBytes(const byte *data, unsigned int size) {
while (size > 0) {
byte b = *data++;
if (b < 16) Serial.print('0');
Serial.print(b, HEX);
if (size > 1) Serial.print(' ');
size = size - 1;
}
}