Displaying outgoing usbMIDI info onboard

Status
Not open for further replies.

monkeybiscuits

Active member
I've got a MIDI controller with several inputs and a 7-segment LED that I'd like to have display the Control Numbers or Values of outgoing usbMIDI messages. "usbMIDI.read()" is only for incoming MIDI, correct?

This code does NOT WORK. This is only how my mind wants it to work.
Code:
#include <MIDI.h>
#include <Bounce.h>

const int pin = 0;
Bounce btn(pin, 50);

void setup(){
  pinMode(pin, INPUT_PULLUP);
  MIDI.begin();
  usbMIDI.setHandleControlChange(OnCC);
}

void loop(){
  btn.update();
  if (btn.fallingEdge()){
    usbMIDI.sendControlChange(20, 127, 1);
  }
  usbMIDI.read();
}

void OnCC(byte channel, byte control, byte value){
  functionThatDisplaysValue(control); 
}

How should I approach this?
 
Last edited:
I'm not familiar with the USB side of the MK20DX but I believe Paul has setup it up so you can either have Serial communication or MIDI communication. Not both.

If you do want both you'll have to look into rawHID which is discussed here

I can't stress enough though that I have almost zero experience on this side of the kinetis MCU. Perhaps someone else can chime in here?
 
Do you need USB Serial or can it be any of the other Serial ports? Serial.begin(31250) indicates that you need a specific speed there, but USB Serial will simply ignore that setting. So I think that you actually need to use Serial1, Serial2, or Serial3.
 
It'll print to the serial monitor (while sending usbMIDI) if I put the call to Serial.println() right after usbMIDI.sendControlChange(). But that's beside the point because I don't really want to display them on the serial port anyway (I'm just trying to debug). I really just want the value of any outgoing MIDI message to be sent to a function I have that will display it on my 7-seg display. I know I could have every function that contains a "usbMIDI.send.....()" return the value and then have something like "functionThatDisplaysValue(myInput.read())" for every single input I have but that seems messy and inefficient. Isn't there just a way to catch outgoing MIDI messages and snag their values?

Sorry, I guess it doesn't help to post the simple version of the problem. MIDI is actually being sent from several different read() functions outside the sketch and the display() function is in a separate library. I'll post more code...
 
Last edited:
Um...never mind. I guess it's not so unreasonable to have a read() function actually return a value and then have a for loop that calls the display() function for each of those inputs...I'll show myself out.
 
Um...never mind. I guess it's not so unreasonable to have a read() function actually return a value and then have a for loop that calls the display() function for each of those inputs...I'll show myself out.
I like it. Often just writing the question down starts the brain off on another investigative track. Yes, for debugging purposes just insert a Serial.println(/*value just read*/); after reading the value. easy, but remove/comment out once debugged.
 
Status
Not open for further replies.
Back
Top