Error: 'usbMIDI' was not declared in this scope

Hello!
I'm doing a project about Arduino in the school and I chosed to do the Mini UNTZtrument MIDI project. I have a problem with the code, more specifically with the library MIDIUSB. I wanted to ask if you could help me with this problem, please. Thank you very much.

#include <Wire.h>
#include <Adafruit_Trellis.h>

#define LED     13 // Pin for heartbeat LED (shows code is working)
#define CHANNEL 1  // MIDI channel number

Adafruit_Trellis trellis;

uint8_t       heart        = 0;  // Heartbeat LED counter
unsigned long prevReadTime = 0L; // Keypad polling timer
uint8_t       mod;
uint8_t       vel;
uint8_t       fxc;
uint8_t       rate;  

uint8_t note[] = {
  60, 61, 62, 63,
  56, 57, 58, 59,
  52, 53, 54, 55,
  48, 49, 50, 51
};

void setup() {
  pinMode(LED, OUTPUT);
  trellis.begin(0x70); // Pass I2C address
#ifdef __AVR__
  // Default Arduino I2C speed is 100 KHz, but the HT16K33 supports
  // 400 KHz.  We can force this for faster read & refresh, but may
  // break compatibility with other I2C devices...so be prepared to
  // comment this out, or save & restore value as needed.
  TWBR = 12;
#endif
  trellis.clear();
  trellis.writeDisplay();
  mod = map(analogRead(0), 0, 1023, 0, 127);
  vel = map(analogRead(1), 0, 1023, 0, 127);
  fxc = map(analogRead(2), 0, 1023, 0, 127);
  rate = map(analogRead(3),0, 1023, 0, 127);
  usbMIDI.sendControlChange(1, mod, CHANNEL);
  usbMIDI.sendControlChange(11, vel, CHANNEL);
  usbMIDI.sendControlChange(12, fxc, CHANNEL);
  usbMIDI.sendControlChange(13, rate, CHANNEL);
}

void loop() {
  unsigned long t = millis();
  if((t - prevReadTime) >= 20L) { // 20ms = min Trellis poll time
    if(trellis.readSwitches()) {  // Button state change?
      
      for(uint8_t i=0; i<16; i++) { // For each button...
        if(trellis.justPressed(i)) {
          usbMIDI.sendNoteOn(note[i], 127, CHANNEL);
          
          trellis.setLED(i);
        } else if(trellis.justReleased(i)) {
          usbMIDI.sendNoteOff(note[i], 0, CHANNEL);
          trellis.clrLED(i);
        }
      }
      trellis.writeDisplay();
    }
    uint8_t newModulation = map(analogRead(0), 0, 1023, 0, 127);
    if(mod != newModulation) {
      mod = newModulation;
      usbMIDI.sendControlChange(1, mod, CHANNEL);
    }
    uint8_t newVelocity = map(analogRead(1), 0, 1023, 0, 127);
    if(vel != newVelocity) {
      vel = newVelocity;
      usbMIDI.sendControlChange(11, vel, CHANNEL);
    }
    uint8_t newEffect = map(analogRead(2), 0, 1023, 0, 127);
    if(fxc != newEffect) {
      fxc = newEffect;
      usbMIDI.sendControlChange(12, fxc, CHANNEL);
    }
    uint8_t newRate = map(analogRead(3), 0, 1023, 0, 127);
    if(rate !=newRate) {
      rate = newRate;
      usbMIDI.sendControlChange(13, rate, CHANNEL);
    }
    prevReadTime = t;
    digitalWrite(LED, ++heart & 32); // Blink = alive
  }
  while(usbMIDI.read()); // Discard incoming MIDI messages
}

The mistake that appears is:

C:\Users\Alumnos\Documents\Arduino\sketch_oct07a\sketch_oct07a.ino: In function 'void setup()':

sketch_oct07a:39:3: error: 'usbMIDI' was not declared in this scope

usbMIDI.sendControlChange(1, mod, CHANNEL);

^

C:\Users\Alumnos\Documents\Arduino\sketch_oct07a\sketch_oct07a.ino: In function 'void loop()':

sketch_oct07a:52:11: error: 'usbMIDI' was not declared in this scope

usbMIDI.sendNoteOn(note*, 127, CHANNEL);*

  • ^*
    sketch_oct07a:56:11: error: 'usbMIDI' was not declared in this scope
    _ usbMIDI.sendNoteOff(note*, 0, CHANNEL);_
    _
    ^_
    sketch_oct07a:65:7: error: 'usbMIDI' was not declared in this scope
    _
    usbMIDI.sendControlChange(1, mod, CHANNEL);_
    _
    ^_
    sketch_oct07a:70:7: error: 'usbMIDI' was not declared in this scope
    _
    usbMIDI.sendControlChange(11, vel, CHANNEL);_
    _
    ^_
    sketch_oct07a:75:7: error: 'usbMIDI' was not declared in this scope
    _
    usbMIDI.sendControlChange(12, fxc, CHANNEL);_
    _
    ^_
    sketch_oct07a:80:7: error: 'usbMIDI' was not declared in this scope
    _
    usbMIDI.sendControlChange(13, rate, CHANNEL);_
    _
    ^_
    sketch_oct07a:85:9: error: 'usbMIDI' was not declared in this scope
    _
    while(usbMIDI.read()); // Discard incoming MIDI messages*_
    * ^*
    exit status 1
    'usbMIDI' was not declared in this scope

What board are you using? IIRC, the Trellis originally used a port from the Teensy 2 Core that worked for the Arduino Leonardo, because the Arduino core didn't support USB MIDI.
Since we now have PluggableUSB in the official Arduino Leonardo core, you can just use the MIDIUSB library instead of the Teensy usbMIDI library. Have a look at the examples that come with MIDIUSB library, and replace all usbMIDI lines with the corresponding MIDIUSB function.

Pieter