Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 2 of 2

Thread: usbMIDI was not declared in this scope?

  1. #1

    usbMIDI was not declared in this scope?

    Hello,
    I have been trying to send MIDI data over usb into the teensy 4.0. However, I cant wrap my head around the error message I am receiving "'usbMIDI' was not declared in this scope". I will post my code down below but I have included the MIDI.h library and my IDE is updated to version 1.56. I am using the boilerplate "inputFunctionsBasic" example from the examples tab. If anyone else has had similar issues I would love to hear your potential fixes.

    Thank you
    Code:
    #include <MIDI.h>
    
    
    void setup() {
      Serial.begin(115200);
      usbMIDI.setHandleNoteOn(myNoteOn);
      usbMIDI.setHandleNoteOff(myNoteOff);
      usbMIDI.setHandleControlChange(myControlChange);
    }
    
    void loop() {
      // The handler functions are called when usbMIDI reads data.  They
      // will not be called automatically.  You must call usbMIDI.read()
      // regularly from loop() for usbMIDI to actually read incoming
      // data and run the handler functions as messages arrive.
      usbMIDI.read();
    }
    
    
    void myNoteOn(byte channel, byte note, byte velocity) {
      // When using MIDIx4 or MIDIx16, usbMIDI.getCable() can be used
      // to read which of the virtual MIDI cables received this message.
      Serial.print("Note On, ch=");
      Serial.print(channel, DEC);
      Serial.print(", note=");
      Serial.print(note, DEC);
      Serial.print(", velocity=");
      Serial.println(velocity, DEC);
    }
    
    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.println(velocity, DEC);
    }
    
    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.println(value, DEC);
    }

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    28,001
    Usually usbMIDI not in scope means you need to click Tools > USB Type and configure the USB to be MIDI.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •