Skip to content

Instantly share code, notes, and snippets.

@cowboy
Created August 23, 2022 04:36
Show Gist options
  • Select an option

  • Save cowboy/f764ca1c6ce163f62f06fd0140c932c6 to your computer and use it in GitHub Desktop.

Select an option

Save cowboy/f764ca1c6ce163f62f06fd0140c932c6 to your computer and use it in GitHub Desktop.

Revisions

  1. cowboy created this gist Aug 23, 2022.
    37 changes: 37 additions & 0 deletions teensy-41-usbmidi-issue
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@
    // Settings:
    // Tools > Board = "Teensy 4.1"
    // Tools > USB Type to "MIDI"

    #include <USBHost_t36.h> // access to USB MIDI devices (plugged into 2nd USB port)

    // Create the ports for USB devices plugged into Teensy's 2nd USB port (via hubs)
    USBHost myusb;
    USBHub hub1(myusb);
    MIDIDevice midiDevice(myusb);

    void setup() {
    pinMode(LED_BUILTIN, OUTPUT);
    digitalWriteFast(LED_BUILTIN, HIGH);
    delay(100);
    digitalWriteFast(LED_BUILTIN, LOW);
    delay(100);
    digitalWriteFast(LED_BUILTIN, HIGH);
    delay(100);
    digitalWriteFast(LED_BUILTIN, LOW);

    myusb.begin();
    }

    void loop() {
    // Read messages arriving from the (up to) 4 USB devices plugged into the USB Host port
    while (midiDevice.read()) {
    uint8_t type = midiDevice.getType();
    uint8_t data1 = midiDevice.getData1();
    uint8_t data2 = midiDevice.getData2();
    uint8_t channel = midiDevice.getChannel();
    usbMIDI.send(type, data1, data2, channel, 0);
    }

    // Read messages the PC (upstream host) sends and ignore them
    while (usbMIDI.read());
    }