I've attached the USB host cable to the USB Host pins on the Teensy 4.1, my midi controller comes on when plugged into it and I've created this simple sketch to print out the CC number of any messages received, however it's not printing anything. This code has been cobbled together from bits I've found online, not sure if its correct or not but it compiles ok....
C++:
#include <USBHost_t36.h>
#include <MIDI.h>
USBHost myusb;
void myNoteOn(byte channel, byte note, byte velocity) {}
void myNoteOff(byte channel, byte note, byte velocity) {}
void myAfterTouchPoly(byte channel, byte note, byte velocity) {}
void myControlChange(byte channel, byte control, byte value) {
Serial.println("CC Received");
byte type = usbMIDI.getType();
if (type == midi::ControlChange) {
byte channel = usbMIDI.getChannel();
byte ccNumber = usbMIDI.getData1();
Serial.print("Received CC number: ");
Serial.println(ccNumber);
}
}
void myProgramChange(byte channel, byte program) {}
void myAfterTouch(byte channel, byte pressure) {}
void myPitchChange(byte channel, int pitch) {}
void mySystemExclusiveChunk(const byte *data, uint16_t length, bool last) {}
void mySystemExclusive(byte *data, unsigned int length) {}
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(byte realtimebyte) {}
void setup() {
Serial.begin(9600);
usbMIDI.setHandleNoteOff(myNoteOff);
usbMIDI.setHandleNoteOn(myNoteOn);
usbMIDI.setHandleAfterTouchPoly(myAfterTouchPoly);
usbMIDI.setHandleControlChange(myControlChange);
usbMIDI.setHandleProgramChange(myProgramChange);
usbMIDI.setHandleAfterTouch(myAfterTouch);
usbMIDI.setHandlePitchChange(myPitchChange);
usbMIDI.setHandleSystemExclusive(mySystemExclusiveChunk);
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);
myusb.begin();
}
void loop() {
myusb.Task();
usbMIDI.read();
//Serial.println("Reading MIDI...");
delay(10);
}
Last edited: