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

Thread: Need help making Trellis send MIDI on/off messages

  1. #1
    Junior Member
    Join Date
    Aug 2020
    Posts
    14

    Need help making Trellis send MIDI on/off messages

    Hello,

    I want to send MIDI on/off messages with the Trellis. According to those on the internet, it's super easy. I'm finding it hard. The code I'm using is the Trellis Test that comes in the Trellis library, with MIDI code copied from another basic Trellis library that doesn't work.

    The Trellis Test code aspect of this sketch still functions as intended, but I get no MIDI reading when using the MIDI Monitor 2 software. Please help. Thanks.

    Code:
    #include <Wire.h>
    #include "Adafruit_Trellis.h"
    #include <MIDI.h>
    
    #define MOMENTARY 0
    #define MODE MOMENTARY
    #define NUMTRELLIS 1
    #define numKeys (NUMTRELLIS * 16)
    #define INTPIN 13
    
    Adafruit_Trellis matrix0 = Adafruit_Trellis();
    Adafruit_TrellisSet trellis = Adafruit_TrellisSet(&matrix0);
    
    int velocity = 100;
    int noteON = 144;
    int noteOFF = 128;
    
    void setup() {
        pinMode(INTPIN, INPUT);
      digitalWrite(INTPIN, HIGH);
    }
    void loop() {
      delay(30);
      if (MODE == MOMENTARY) {
      if (trellis.readSwitches()) {
          for (int8_t i=0; i<numKeys; i++) {
            if (trellis.justPressed(i)) {
              MIDImessage(noteON, 48+1, velocity);
              trellis.setLED(i);      
            }
            if (trellis.justReleased(i)) {
              MIDImessage(noteOFF, 48+i, velocity);
              trellis.clrLED(i);
            }
          }
          trellis.writeDisplay();
      }
     }
    }
    
    void MIDImessage(int command, int MIDInote, int MIDIvelocity) {
      Serial.write(command);
      Serial.write(MIDInote);
      Serial.write(MIDIvelocity);
    }

  2. #2
    Senior Member
    Join Date
    Aug 2019
    Location
    Melbourne Australia
    Posts
    160
    You might try this :-

    Code:
    #include <Wire.h>
    #include "Adafruit_Trellis.h"
    #include <MIDI.h>
    // then we need to tell the library which Uart to use
    // So, assuming you have connected Midi I/O circuitry to TX/RX 1
    
    MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI);
    
    #define MOMENTARY 0
    #define MODE MOMENTARY
    #define NUMTRELLIS 1
    #define numKeys (NUMTRELLIS * 16)
    #define INTPIN 13
    
    Adafruit_Trellis matrix0 = Adafruit_Trellis();
    Adafruit_TrellisSet trellis = Adafruit_TrellisSet(&matrix0);
    
    int velocity = 100;
    int noteON = 144; //not used
    int noteOFF = 128;//not used
    int channel = 1; // A channel to send on
    void setup() {
        pinMode(INTPIN, INPUT);
      digitalWrite(INTPIN, HIGH);
    
    //  Then we need to wake the Midi library up
        MIDI.begin(MIDI_CHANNEL_OMNI); 
    
    }
    void loop() {
        while (MIDI.read())
        {
         // controllers must call .read() to keep the queue clear even if they are not responding to MIDI
        }
    
      delay(30);
      if (MODE == MOMENTARY) {
      if (trellis.readSwitches()) {
          for (int8_t i=0; i<numKeys; i++) {
            if (trellis.justPressed(i)) {
    //          MIDImessage(noteON, 48+1, velocity);
          MIDI.sendNoteOn(48+i, velocity, channel);
    
              trellis.setLED(i);      
            }
            if (trellis.justReleased(i)) {
    //          MIDImessage(noteOFF, 48+i, velocity);
          MIDI.sendNoteOff(48+i, velocity, channel);
    
              trellis.clrLED(i);
            }
          }
          trellis.writeDisplay();
      }
     }
    }
    // Not using this part
    //void MIDImessage(int command, int MIDInote, int MIDIvelocity) {
    //  Serial.write(command);
    //  Serial.write(MIDInote);
    // Serial.write(MIDIvelocity);
    //}
    I think will work, not tested here.

Posting Permissions

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