Send 1 Sysex message depending on momentary switch State

Status
Not open for further replies.
Solved.
Just did a min definition:
mod2 = min(mod2, 63); // This way Y Center-Up will only send from 0 till 63 values
//mod = min(mod2,63);

Now, to calm down that pitchbend a bit more, arg
I alread wired a 1uf cap between pin and ground and it calmed big time, but it is still not enough.
 
Last edited:
Hi guys.
After some months not touching my Teensy, I am now back to business.
I can already have buttons built into the ili9488/ft6206 and send Sysex and CC to my Korg M3 together with the joystick XY CC#'s.
I am now trying to delve more on this, once that it seems to be easier than i thought at first for what i have read here. (Easy = Not for me, Lol)
What I am trying now is to make the SW1 and SW2 buttons (physical ones removed and now in the touchscreen only) on the main topic of this thread, get the right values in accordance with some sysex array received.
And, why am i asking this?
Simply because i just noticed that the Korg M3 synthesizer always sends the sysex that i need everytime there is a program/combi/Seq change.
This is what Midiox receives when there is some PC:

Code:
SYSX: F0 42 30 75 24 00 F7
00007C7E   1  --     B0    50    00    1  ---  Control Change   
00007C7E   1  --     B0    51    00    1  ---  Control Change

How can i use this in teensy to make the buttons get that 50 B0 and 51 B0 values? I think that if ii could get this print in the serial monitor it would be easier to see what it does and work from there, with your help of course.
I have never worked with arrays and this is my first project envolving programming.

My current sketch:
Code:
// include the ResponsiveAnalogRead library for analog smoothing
#include <ResponsiveAnalogRead.h>
#include <Bounce.h>  // Bounce library makes button change detection easy
// ******CONSTANT VALUES******** - customize code behaviour here!


// SET THESE SIX VALUES FOR JOYSTICK!
const int pitchPin = 0; // PIN numbers ** MUST CHANGE!
const int modPin = 1;
const int modPin2 = 1;
const int pitchMaxRaw = 1019; // Max reading with full bend up... as raw 10-bit value
const int modMaxRaw = 1019; // Max reading full mod down


// SET THESE VALUES FOR RIBBON
//const int ribbonPin = touch_pressed; // Max reading on right side... as raw 10-bit value
const int ribbonMaxRaw = 474; // Max reading on right side... as raw 10-bit value
//


int Button1 = 0; //This is the default "Button Off" and 1 is "Button On"
int Button2 = 0; //This is the default "Button Off" and 1 is "Button On"
int OldButton1 = 0; //Variable to store button1 old value
int OldButton2 = 0; //Variable to store button2 old value
byte data1On[] = {0xf0, 0x42, 0x30, 0x75, 0x41, 0x00, 0x00, 0x01, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x01, 0xf7};
byte data1Off[] = {0xf0, 0x42, 0x30, 0x75, 0x41, 0x00, 0x00, 0x01, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf7};
byte data2On[] = {0xf0, 0x42, 0x30, 0x75, 0x41, 0x00, 0x00, 0x01, 0x00, 0x0B, 0x00, 0x00, 0x00, 0x00, 0x01, 0xf7};
byte data2Off[] = {0xf0, 0x42, 0x30, 0x75, 0x41, 0x00, 0x00, 0x01, 0x00, 0x0B, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf7};
byte progMode[] = {0xf0, 0x42, 0x30, 0x75, 0x4E, 0x02, 0xf7};
byte combiMode[] = {0xf0, 0x42, 0x30, 0x75, 0x4E, 0x00, 0xf7};
byte seqMode[] = {0xf0, 0x42, 0x30, 0x75, 0x4E, 0x04, 0xf7};
byte modeRequest[] = {0xf0, 0x42, 0x30, 0x75, 0x12, 0x00, 0xf7};


const int channel = 1; // MIDI channel
const int MIDIdelay = 5; // will update MIDI only if this many milliseconds have passed
//******VARIABLES***********
// data variables and a lagged copy to compare before updating MIDI value
int pitch;
int mod;
int mod2;
int pitchRaw;
int modRaw;
int modRaw2;
int pitchLag;
int modLag;
int modLag2;
int ribbon;
int ribbonRaw;
int ribbonLag;


elapsedMillis pitchUpdate;
elapsedMillis modUpdate;
elapsedMillis modUpdate2;
elapsedMillis ribbonUpdate;


// ititialize the ReponsiveAnalogRead objects
ResponsiveAnalogRead readPitch = {pitchPin, true};
ResponsiveAnalogRead readMod = {modPin, true};
ResponsiveAnalogRead readMod2 = {modPin2, true};


#include <Adafruit_GFX.h>    // Core graphics library


#define LCD_ROTATION  1        //should work in all rotations
#define USE_READID    0        //Adafruit and ILI9488 can't read ID
//#include <MCUFRIEND_kbv.h>     // Hardware-specific library
//MCUFRIEND_kbv tft;
//#include <Adafruit_ILI9341.h>   // Hardware-specific library
//Adafruit_ILI9341 tft(10, 9, 8);
//#include <HX8347D_kbv.h>        // Hardware-specific library
//HX8347D_kbv tft;
#include <ILI9488.h>            // Hardware-specific library
ILI9488 tft(10, 9, 8);
//#include <ILI9488_kbv.h>            // Hardware-specific library
//ILI9488_kbv tft;


extern void Touch_initialise(int aspect, int wid, int ht);
extern bool Touch_getXY(void);
bool touch_pressed;
int pixel_x, pixel_y;
boolean SW1on = false;
boolean SW2on = false;
boolean Progon = false;
boolean Combion = false;
boolean Seqon = false;
boolean ribbonCtrl = false;


// Color definitions
#define TFT_BLACK       0x0000      /*   0,   0,   0 */
#define TFT_NAVY        0x000F      /*   0,   0, 128 */
#define TFT_DARKGREEN   0x03E0      /*   0, 128,   0 */
#define TFT_DARKCYAN    0x03EF      /*   0, 128, 128 */
#define TFT_MAROON      0x7800      /* 128,   0,   0 */
#define TFT_PURPLE      0x780F      /* 128,   0, 128 */
#define TFT_OLIVE       0x7BE0      /* 128, 128,   0 */
#define TFT_LIGHTGREY   0xC618      /* 192, 192, 192 */
#define TFT_DARKGREY    0x7BEF      /* 128, 128, 128 */
#define TFT_BLUE        0x001F      /*   0,   0, 255 */
#define TFT_GREEN       0x07E0      /*   0, 255,   0 */
#define TFT_CYAN        0x07FF      /*   0, 255, 255 */
#define TFT_RED         0xF800      /* 255,   0,   0 */
#define TFT_RED2        0xF88D      /* 254,  18, 106 */
#define TFT_MAGENTA     0xF81F      /* 255,   0, 255 */
#define TFT_YELLOW      0xFFE0      /* 255, 255,   0 */
#define TFT_WHITE       0xFFFF      /* 255, 255, 255 */
#define TFT_ORANGE      0xFD20      /* 255, 165,   0 */
#define TFT_ORANGE2     0xFB20      /* 254, 102,   1 */
#define TFT_GREENYELLOW 0xAFE5      /* 173, 255,  47 */
#define TFT_PINK        0xF81F


/******************* UI details */


#define PROGFRAME_X 20
#define PROGFRAME_Y 10
#define PROGFRAME_W 90
#define PROGFRAME_H 50


#define PROGBUTTON_X PROGFRAME_X
#define PROGBUTTON_Y PROGFRAME_Y
#define PROGBUTTON_W PROGFRAME_W
#define PROGBUTTON_H PROGFRAME_H


#define COMBIFRAME_X 200
#define COMBIFRAME_Y 10
#define COMBIFRAME_W 90
#define COMBIFRAME_H 50


#define COMBIBUTTON_X COMBIFRAME_X
#define COMBIBUTTON_Y COMBIFRAME_Y
#define COMBIBUTTON_W COMBIFRAME_W
#define COMBIBUTTON_H COMBIFRAME_H


#define SEQFRAME_X 370
#define SEQFRAME_Y 10
#define SEQFRAME_W 90
#define SEQFRAME_H 50


#define SEQBUTTON_X SEQFRAME_X
#define SEQBUTTON_Y SEQFRAME_Y
#define SEQBUTTON_W SEQFRAME_W
#define SEQBUTTON_H SEQFRAME_H


#define SW1FRAME_X 90
#define SW1FRAME_Y 110
#define SW1FRAME_W 130
#define SW1FRAME_H 70


#define SW1BUTTON_X SW1FRAME_X
#define SW1BUTTON_Y SW1FRAME_Y
#define SW1BUTTON_W SW1FRAME_W
#define SW1BUTTON_H SW1FRAME_H


#define SW2FRAME_X 310
#define SW2FRAME_Y 110
#define SW2FRAME_W 130
#define SW2FRAME_H 70


#define SW2BUTTON_X SW2FRAME_X
#define SW2BUTTON_Y SW2FRAME_Y
#define SW2BUTTON_W SW2FRAME_W
#define SW2BUTTON_H SW2FRAME_H


#define RIBBONFRAME_X 10
#define RIBBONFRAME_Y 240
#define RIBBONFRAME_W 470
#define RIBBONFRAME_H 70


#define RIBBON_X RIBBONFRAME_X
#define RIBBON_Y RIBBONFRAME_Y
#define RIBBON_W RIBBONFRAME_W
#define RIBBON_H RIBBONFRAME_H


void progBtn()
{ 
  tft.drawRect(PROGBUTTON_X, PROGBUTTON_Y, PROGBUTTON_W, PROGBUTTON_H, TFT_WHITE);
  tft.fillRect(PROGBUTTON_X, PROGBUTTON_Y, PROGBUTTON_W, PROGBUTTON_H, TFT_WHITE);
  tft.setCursor(40, 25);
  tft.setTextColor(TFT_BLACK);
  tft.setTextSize(2);
  tft.println("Prog");
  usbMIDI.sendSysEx(7, modeRequest, true); //The Sysex to change to Program Mode in Korg M3
  Progon = false;
}
void combiBtn()
{ 
  tft.drawRect(COMBIBUTTON_X, COMBIBUTTON_Y, COMBIBUTTON_W, COMBIBUTTON_H, TFT_WHITE);
  tft.fillRect(COMBIBUTTON_X, COMBIBUTTON_Y, COMBIBUTTON_W, COMBIBUTTON_H, TFT_WHITE);
  tft.setCursor(220, 25);
  tft.setTextColor(TFT_BLACK);
  tft.setTextSize(2);
  tft.println("Combi");
  usbMIDI.sendSysEx(7, combiMode, true); //The Sysex to change to Combi Mode in Korg M3
  Combion = false;
}
void seqBtn()
{ 
  tft.drawRect(SEQBUTTON_X, SEQBUTTON_Y, SEQBUTTON_W, SEQBUTTON_H, TFT_WHITE);
  tft.fillRect(SEQBUTTON_X, SEQBUTTON_Y, SEQBUTTON_W, SEQBUTTON_H, TFT_WHITE);
  tft.setCursor(400, 25);
  tft.setTextColor(TFT_BLACK);
  tft.setTextSize(2);
  tft.println("Seq");
  usbMIDI.sendSysEx(7, seqMode, true); //The Sysex to change to SEQ Mode in Korg M3
  Seqon = false;
}
void sw1Btn()
{ 
  tft.drawRect(SW1BUTTON_X, SW1BUTTON_Y, SW1BUTTON_W, SW1BUTTON_H, TFT_DARKGREY);
  tft.fillRect(SW1BUTTON_X, SW1BUTTON_Y, SW1BUTTON_W, SW1BUTTON_H, TFT_RED);
  tft.setCursor(160, 140);
  tft.setTextColor(TFT_WHITE);
  tft.setTextSize(2);
  tft.println("SW1");
  SW1on = false;
}
void sw2Btn()
{ 
  tft.drawRect(SW2BUTTON_X, SW2BUTTON_Y, SW2BUTTON_W, SW2BUTTON_H, TFT_DARKGREY);
  tft.fillRect(SW2BUTTON_X, SW2BUTTON_Y, SW2BUTTON_W, SW2BUTTON_H, TFT_RED);
  tft.setCursor(340,140);
  tft.setTextColor(TFT_WHITE);
  tft.setTextSize(2);
  tft.println("SW2");
  SW2on = false;
}
void rbCtrl()
{ 
  tft.drawRect(RIBBON_X, RIBBON_Y, RIBBON_W, RIBBON_H, TFT_LIGHTGREY);
  tft.fillRect(RIBBON_X, RIBBON_Y, RIBBON_W, RIBBON_H, TFT_LIGHTGREY);
  tft.setCursor(10,240);
    //remap to output data and send if changed and MIDIdelay has lapsed since last update for that parameter
    ribbon = map(pixel_x, 11, 474, 0, 127);
    ribbon = max(ribbon, 0); // need this now that the bottom isn't zero
    ribbon = min(ribbon, 127); // cap to avoid overflow
    if (abs(ribbon - ribbonLag) > 0 && ribbonUpdate > MIDIdelay ) {
      ribbonLag = ribbon;
    usbMIDI.sendControlChange(16, ribbon, channel);
      ribbonUpdate = 0;
    }
  ribbonCtrl = false;
}




void setup(void)
{
    Serial.begin(9600);
    Serial.println(F("TFT LCD test"));


    tft.begin();


    int aspect = LCD_ROTATION;   //PORTRAIT
    tft.setRotation(aspect);
    Touch_initialise(aspect, tft.width(), tft.height());  //.kbv external function
    tft.fillScreen(TFT_BLACK);
    


    // create 'SW1 Switch'
    tft.drawRect(SW1BUTTON_X, SW1BUTTON_Y, SW1BUTTON_W, SW1BUTTON_H, TFT_DARKGREY);
    tft.fillRect(SW1BUTTON_X, SW1BUTTON_Y, SW1BUTTON_W, SW1BUTTON_H, TFT_RED);
    tft.setCursor(155, 140);
    tft.setTextColor(TFT_BLACK);
    tft.setTextSize(2);
    tft.print("SW1");


    // create 'SW2 Switch'
    tft.drawRect(SW2BUTTON_X, SW2BUTTON_Y, SW2BUTTON_W, SW2BUTTON_H, TFT_DARKGREY);
    tft.fillRect(SW2BUTTON_X, SW2BUTTON_Y, SW2BUTTON_W, SW2BUTTON_H, TFT_RED);
    tft.setCursor(340, 140);
    tft.setTextColor(TFT_BLACK);
    tft.setTextSize(2);
    tft.print("SW2");


    // create 'PROG Switch'
    tft.drawRect(PROGBUTTON_X, PROGBUTTON_Y, PROGBUTTON_W, PROGBUTTON_H, TFT_DARKGREY);
    tft.fillRect(PROGBUTTON_X, PROGBUTTON_Y, PROGBUTTON_W, PROGBUTTON_H, TFT_BLUE);
    tft.setCursor(40, 25);
    tft.setTextColor(TFT_BLACK);
    tft.setTextSize(2);
    tft.print("Prog");    


    // create 'COMBI Switch'
    tft.drawRect(COMBIBUTTON_X, COMBIBUTTON_Y, COMBIBUTTON_W, COMBIBUTTON_H, TFT_DARKGREY);
    tft.fillRect(COMBIBUTTON_X, COMBIBUTTON_Y, COMBIBUTTON_W, COMBIBUTTON_H, TFT_RED);
    tft.setCursor(220, 25);
    tft.setTextColor(TFT_BLACK);
    tft.setTextSize(2);
    tft.print("Combi");
     
    // create 'SEQ Switch'
    tft.drawRect(SEQBUTTON_X, SEQBUTTON_Y, SEQBUTTON_W, SEQBUTTON_H, TFT_DARKGREY);
    tft.fillRect(SEQBUTTON_X, SEQBUTTON_Y, SEQBUTTON_W, SEQBUTTON_H, TFT_YELLOW);
    tft.setCursor(400, 25);
    tft.setTextColor(TFT_BLACK);
    tft.setTextSize(2);
    tft.print("Seq");     


    // create 'Ribbon Emulator field'
    tft.drawRect(RIBBON_X, RIBBON_Y, RIBBON_W, RIBBON_H, TFT_DARKGREY);
    tft.fillRect(RIBBON_X, RIBBON_Y, RIBBON_W, RIBBON_H, TFT_LIGHTGREY);
}


void loop(void)
{


  usbMIDI.read();
  if (usbMIDI.read() == 1 && usbMIDI.getType() == 7 ) {//check for sysex 
   const byte *pSysExArray = usbMIDI.getSysExArray(); //capture data
    Serial.println(*pSysExArray);
  }
    int x = -1, y = -1;   //regular pixel coordinates
    touch_pressed = Touch_getXY();  //external function
#if 0
    Serial.print("X="); Serial.print(pixel_x); 
    Serial.print(" Y="); Serial.print(pixel_y); 
    Serial.print(" Z="); Serial.print(touch_pressed); 
    Serial.println("");
#endif
    if (touch_pressed) {
        x = pixel_x;      //copy global variable
        y = pixel_y;
    }


    {
      if((x > PROGBUTTON_X) && (x < (PROGBUTTON_X + PROGBUTTON_W))) {
        if ((y > PROGBUTTON_Y) && (y <= (PROGBUTTON_Y + PROGBUTTON_H))) {
          Serial.println("PROG btn hit"); 
          delay(100); // UI debouncing
          progBtn();
        }
      }
    }
{
      if((x > COMBIBUTTON_X) && (x < (COMBIBUTTON_X + COMBIBUTTON_W))) {
        if ((y > COMBIBUTTON_Y) && (y <= (COMBIBUTTON_Y + COMBIBUTTON_H))) {
          Serial.println("Combi btn hit"); 
          delay(100); // UI debouncing
          combiBtn();
        }
      }
    }
{
      if((x > SEQBUTTON_X) && (x < (SEQBUTTON_X + SEQBUTTON_W))) {
        if ((y > SEQBUTTON_Y) && (y <= (SEQBUTTON_Y + SEQBUTTON_H))) {
          Serial.println("Seq btn hit"); 
          delay(100); // UI debouncing
          seqBtn();
        }
      }
    }
    
{
      if((x > SW1BUTTON_X) && (x < (SW1BUTTON_X + SW1BUTTON_W))) {
        if ((y > SW1BUTTON_Y) && (y <= (SW1BUTTON_Y + SW1BUTTON_H))) {
          Serial.println("SW1 btn hit"); 
          delay(100); // UI debouncing
          sw1Btn();
        }
      }
    }


{
      if((x > SW2BUTTON_X) && (x < (SW2BUTTON_X + SW2BUTTON_W))) {
        if ((y > SW2BUTTON_Y) && (y <= (SW2BUTTON_Y + SW2BUTTON_H))) {
          Serial.println("SW2 btn hit"); 
          delay(100); // UI debouncing
          sw2Btn();
        }
      }
    } 
{
      if((x > RIBBON_X) && (x < (RIBBON_X + RIBBON_W))) {
        if ((y > RIBBON_Y) && (y <= (RIBBON_Y + RIBBON_H))) {
          Serial.println("Ribbon pressed"); 
          Serial.println(pixel_x);
          Serial.println(ribbon);       
          delay(100); // UI debouncing
          rbCtrl();
        }
      }
    } 
    
  }



This part is my first try to do the array printing without luck:
Code:
usbMIDI.read();
  if (usbMIDI.read() == 1 && usbMIDI.getType() == 7 ) {//check for sysex 
   const byte *pSysExArray = usbMIDI.getSysExArray(); //capture data
    Serial.println(*pSysExArray);

I would appreciate a lot all the help i can get.

PS:
The SW1 and SW2 buttons have no sysex assigned for testing purposes but its just a matter of putting the sysex dataxon or dataxoff in the sw1 and sw2 functions.
The joystick part is not there but thats just a matter of copying it from the backup sketch.
 
Last edited:
Code:
SYSX: F0 42 30 75 24 00 F7
00007C7E   1  --     B0    50    00    1  ---  Control Change   
00007C7E   1  --     B0    51    00    1  ---  Control Change

Those sysex and cc lines i put in the previous post must have been trunckated or something, once that reading them will be misleading.
I will put a new captured ones later in the afternoon.

When I said:
Simply because i just noticed that the Korg M3 synthesizer always sends the sysex that i need everytime there is a program/combi/Seq change.
This is what Midiox receives when there is some PC:

It should have been:
Simply because i just noticed that the Korg M3 synthesizer always sends the sysex that i need (and more that i need for now) everytime there is a program/combi/Seq change.

It really sends the lines i mentioned BUT they are the LAST 2 lines of the CC result (The values are not always the same as above, there are some presets that have and F7 in the "00" byte p.e.). I remember that the first 3 ones are MSB, LSB and the Preset name one, for each channel. I'm only interested in the ones for the general channel (Channel 1 in my case).
 
getType() == 7
This was reluctantly changed for usbMIDI recently to match MIDI library.

The '7' should be '0xF7' or 'usbMIDI.SystemExclusive'
 
Last edited:
Not sure what your asking about right now....

Are you trying to use the CC values sent from the Korg? If so it's not sysex it's regular midi.

You seem to want to associate the buttons with these results but that doesn't make sense to me.

If the midi is a result of program changes then why would you need to trigger anything with the buttons (and why are there two of them?).

Could you explain the desired outcome without going into the midi?

Just a high-level explanation of what the button should 'do' for the end user.
 
Hi oddson. No problem, i'll try to explain.
Oh, I know that I need a CC#, but after reading the explanation I think you'll understand why it isn't that simple.

Those 2 buttons are part of the original Korg M3 keyboard. This keyboard has the particular possibility of being separated from it's brain, which is what I have, only the Korg M3 module (brain). That is called the Korg M3M.

These buttons have their own assigned function on each preset. The problem with it is that althought the majority of the presets use CC#80 and CC#81 for SW1 and SW2, there are presets where they have different CC#. That's why I need to do it via sysex, which have special sysex commands for that, but are different if it is a Program a Combi or a Seq (song).
So, for this to work we need to:
1 - Know what is the Mode of the synth at the moment: Prog(ram), Combi(nation), or Seq(uence). So, we send a Mode Request;
2 - The synthesizer answers (Mode Dump);
3 - We analyse this answer (Mode dump);
4 - We send a sysex request to ask for the Prog/Combi/Seq parameters dump; These are different sysex commands depending on the Mode being used;
5 - The synthesizer sends the Prog/Combi/Seq parameters dump;
6 - We read that sysex dump and assign the CC# sent by the dump on the SW1 and SW2 button's functions.
I would like to avoid having to receive a 8000+ byte dump just for this.

--/--
Now, with this discovery of the synth sending all that whenever there is a Program Change changes all that.
We just need to see what it is sending and assign it directly to the SW1 and SW2 buttons. I even think that just reading that first Sysex array is enough. Will only need to make a if statement. But I need to be sure that there are no surprises and will need a hand from you nice fellows on this one. ;)
 
K.. that's the midi part which helps... but can you answer the question. What do the buttons 'do' in end user terms?


BTW - Korg published a midi document for M3. Could take a lot of guesswork out of it.
 
Each button turns on or off the assigned CC#, which can be a Octave Down/Up, a Joystick Y/X freeze, whatever you assign to it.
 
Looks to me like a very short sysex tells the controller to listen for the CC values these parameter buttons should be sending.

There's no way the sysex you've posted contains the CC data as there are only seven bytes and all but one are not conveying new info to the controller.

The first and last are start and end bytes (0xF0 and 0xF7); bytes three and four are the manufacturer and product IDs in hex (respectively). Byte six is zero so only byte five is plausibly carrying new info and it's not sufficient to carry the two CC numbers.

If looks like 0x24 means RESULT REPORT so my guess is this tells the controller to listen for CC numbers to assign to the patch-specific function buttons.

If so you would need a 'flag' variable to tell the code to read the next two control numbers and assign them to a variables to be used in the usbMIDI.sendControlChange() messages for the two buttons. When complete it would reset the flag so any new CC messages are not be read unless the RESULT REPORT message is received again.

If I'm correct this would not be difficult to implement.
 
True.
The sysex i have there are the ones for the mode requests, mode changes and sysex prog/combi/seq dump requests as per the explanation .
I can already see sysex on the serial monitor. Will dig a bit on this and keep you updated!
Thank You.
 
Last edited:
Hi oddson.
I already have that, and that's where I have been studying this thing, but thank you anyway for your invaluable help.
 
cool... if it turns out each one has the same message or there is a small set of messages that indicate CC numbers will be sent with D2=0 to select the target of the special function buttons then flagging a 'listen' for the new CC values in/from the main loop should be relatively simple.


Btw this line:
const byte *pSysExArray = usbMIDI.getSysExArray(); //capture data
...tells me I still have a bunch to learn about pointers in C as I'd have put money that it would not compile or not work but I gather you copied it from functioning source code.
 
hehehe but it does word my friend! That is, it compiles and it does something because I can see values in the serial monitor.
Anyway, that is something I am just trying with a piece of code i found somewhere here in pjrc.

I think i've found out how the M3 behaves.
When it detects a Program Change the synth sends all the CC's for all the channels it has in that Current Combi or Seq preset, whether the PC is sent from outside or from inside the M3. If mentioned PC is sent internally by the M3 buttons or wheel it will also output a MSB-LSB pair of information lines, but only if sent internally, not if said Program Change is sent from outside (like from my StudioLogics Acuna 88 in Input Port 8, p.e).
You can see that in the quoted paste from Midi-Ox for a Combi.


Code:
003C7965   8  --     C0    4F    --    1  ---  PC: Ocarina       
003C95CA   8  --     C0    50    --    1  ---  PC: Lead1(square) 
003C95F4   1  --     B0    50    00    1  ---  Control Change    
003C95F4   1  --     B0    51    00    1  ---  Control Change


Code:
003CBBD0   1  --     B0    00    00    1  ---  CC: Bank MSB      
003CBBD0   1  --     B0    20    0D    1  ---  CC: Bank LSB      
003CBBD0   1  --     C0    4F    --    1  ---  PC: Ocarina       
003CEA28   1  --     B0    00    00    1  ---  CC: Bank MSB      
003CEA28   1  --     B0    20    0D    1  ---  CC: Bank LSB      
003CEA28   1  --     C0    50    --    1  ---  PC: Lead1(square) 
003CEA4C   1  --     B0    50    00    1  ---  Control Change    
003CEA4E   1  --     B0    51    00    1  ---  Control Change
If the preset doesn't have anything assign to the SW1 or SW2 it will only output the PC Preset Number plus (if sent internally) the already MSB/SLB.

This is a Seq (or Song if you whish):
Code:
 TIMESTAMP IN PORT STATUS DATA1 DATA2 CHAN NOTE EVENT               
 00019026  22  --     F0  Buffer:     7 Bytes   System Exclusive      
 SYSX: F0 42 30 75 4E 04 F7
 0001902D   1  --     F0  Buffer:     7 Bytes   System Exclusive      
 SYSX: F0 42 30 75 24 00 F7
 00019033   1  --     F3    00    --   --  ---  Song Select           
 00019033   1  --     F2    00    00   --  ---  Song Position Ptr     
 00019033   1  --     B0    00    00    1  ---  CC: Bank MSB          
 00019033   1  --     B0    20    00    1  ---  CC: Bank LSB          
 00019033   1  --     C0    00    --    1  ---  PC: Acc. Grand Piano  
 00019033   1  --     B0    07    7F    1  ---  CC: Volume            
 00019033   1  --     B0    0A    40    1  ---  CC: PAN               
 00019033   1  --     B0    5D    00    1  ---  CC: Chorus Depth      
 00019033   1  --     B0    5B    00    1  ---  CC: Reverb Depth      
 00019033   1  --     B1    00    00    2  ---  CC: Bank MSB          
 00019033   1  --     B1    20    00    2  ---  CC: Bank LSB          
 00019033   1  --     C1    00    --    2  ---  PC: Acc. Grand Piano  
 00019033   1  --     B1    07    7F    2  ---  CC: Volume            
 00019033   1  --     B1    0A    40    2  ---  CC: PAN               
 00019033   1  --     B1    5D    00    2  ---  CC: Chorus Depth      
 00019033   1  --     B1    5B    00    2  ---  CC: Reverb Depth      
 00019036   1  --     B2    00    00    3  ---  CC: Bank MSB          
 00019036   1  --     B2    20    00    3  ---  CC: Bank LSB          
 00019036   1  --     C2    00    --    3  ---  PC: Acc. Grand Piano  
 00019036   1  --     B2    07    7F    3  ---  CC: Volume            
 00019036   1  --     B2    0A    40    3  ---  CC: PAN               
 00019036   1  --     B2    5D    00    3  ---  CC: Chorus Depth      
 00019036   1  --     B2    5B    00    3  ---  CC: Reverb Depth      
 00019036   1  --     B3    00    00    4  ---  CC: Bank MSB          
 00019036   1  --     B3    20    00    4  ---  CC: Bank LSB          
 00019036   1  --     C3    00    --    4  ---  PC: Acc. Grand Piano  
 00019036   1  --     B3    07    7F    4  ---  CC: Volume            
 00019036   1  --     B3    0A    40    4  ---  CC: PAN               
 00019036   1  --     B3    5D    00    4  ---  CC: Chorus Depth      
 00019036   1  --     B3    5B    00    4  ---  CC: Reverb Depth      
 00019036   1  --     B4    00    00    5  ---  CC: Bank MSB          
 00019036   1  --     B4    20    00    5  ---  CC: Bank LSB          
 00019039   1  --     C4    00    --    5  ---  PC: Acc. Grand Piano  
 00019039   1  --     B4    07    7F    5  ---  CC: Volume            
 00019039   1  --     B4    0A    40    5  ---  CC: PAN               
 00019039   1  --     B4    5D    00    5  ---  CC: Chorus Depth      
 00019039   1  --     B4    5B    00    5  ---  CC: Reverb Depth      
 00019039   1  --     B5    00    00    6  ---  CC: Bank MSB          
 00019039   1  --     B5    20    00    6  ---  CC: Bank LSB          
 00019039   1  --     C5    00    --    6  ---  PC: Acc. Grand Piano  
 00019039   1  --     B5    07    7F    6  ---  CC: Volume            
 00019039   1  --     B5    0A    40    6  ---  CC: PAN               
 00019039   1  --     B5    5D    00    6  ---  CC: Chorus Depth      
 00019039   1  --     B5    5B    00    6  ---  CC: Reverb Depth      
 00019039   1  --     B6    00    00    7  ---  CC: Bank MSB          
 00019039   1  --     B6    20    00    7  ---  CC: Bank LSB          
 00019039   1  --     C6    00    --    7  ---  PC: Acc. Grand Piano  
 00019039   1  --     B6    07    7F    7  ---  CC: Volume            
 0001903C   1  --     B6    0A    40    7  ---  CC: PAN               
 0001903C   1  --     B6    5D    00    7  ---  CC: Chorus Depth      
 0001903C   1  --     B6    5B    00    7  ---  CC: Reverb Depth      
 0001903C   1  --     B7    00    00    8  ---  CC: Bank MSB          
 0001903C   1  --     B7    20    00    8  ---  CC: Bank LSB          
 0001903C   1  --     C7    00    --    8  ---  PC: Acc. Grand Piano  
 0001903C   1  --     B7    07    7F    8  ---  CC: Volume            
 0001903C   1  --     B7    0A    40    8  ---  CC: PAN               
 0001903C   1  --     B7    5D    00    8  ---  CC: Chorus Depth      
 0001903C   1  --     B7    5B    00    8  ---  CC: Reverb Depth      
 0001903C   1  --     B8    00    00    9  ---  CC: Bank MSB          
 0001903C   1  --     B8    20    00    9  ---  CC: Bank LSB          
 0001903C   1  --     C8    00    --    9  ---  PC: Acc. Grand Piano  
 0001903C   1  --     B8    07    7F    9  ---  CC: Volume            
 0001903C   1  --     B8    0A    40    9  ---  CC: PAN               
 0001903C   1  --     B8    5D    00    9  ---  CC: Chorus Depth      
 0001903F   1  --     B8    5B    00    9  ---  CC: Reverb Depth      
 0001903F   1  --     B9    00    00   10  ---  CC: Bank MSB          
 0001903F   1  --     B9    20    00   10  ---  CC: Bank LSB          
 0001903F   1  --     C9    00    --   10  ---  PC: Drums             
 0001903F   1  --     B9    07    7F   10  ---  CC: Volume            
 0001903F   1  --     B9    0A    40   10  ---  CC: PAN               
 0001903F   1  --     B9    5D    00   10  ---  CC: Chorus Depth      
 0001903F   1  --     B9    5B    00   10  ---  CC: Reverb Depth      
 0001903F   1  --     BA    00    00   11  ---  CC: Bank MSB          
 0001903F   1  --     BA    20    00   11  ---  CC: Bank LSB          
 0001903F   1  --     CA    00    --   11  ---  PC: Acc. Grand Piano  
 0001903F   1  --     BA    07    7F   11  ---  CC: Volume            
 0001903F   1  --     BA    0A    40   11  ---  CC: PAN               
 0001903F   1  --     BA    5D    00   11  ---  CC: Chorus Depth      
 0001903F   1  --     BA    5B    00   11  ---  CC: Reverb Depth      
 0001903F   1  --     BB    00    00   12  ---  CC: Bank MSB          
 00019043   1  --     BB    20    00   12  ---  CC: Bank LSB          
 00019043   1  --     CB    00    --   12  ---  PC: Acc. Grand Piano  
 00019043   1  --     BB    07    7F   12  ---  CC: Volume            
 00019043   1  --     BB    0A    40   12  ---  CC: PAN               
 00019043   1  --     BB    5D    00   12  ---  CC: Chorus Depth      
 00019043   1  --     BB    5B    00   12  ---  CC: Reverb Depth      
 00019043   1  --     BC    00    00   13  ---  CC: Bank MSB          
 00019043   1  --     BC    20    00   13  ---  CC: Bank LSB          
 00019043   1  --     CC    00    --   13  ---  PC: Acc. Grand Piano  
 00019043   1  --     BC    07    7F   13  ---  CC: Volume            
 00019043   1  --     BC    0A    40   13  ---  CC: PAN               
 00019043   1  --     BC    5D    00   13  ---  CC: Chorus Depth      
 00019043   1  --     BC    5B    00   13  ---  CC: Reverb Depth      
 00019043   1  --     BD    00    00   14  ---  CC: Bank MSB          
 00019043   1  --     BD    20    00   14  ---  CC: Bank LSB          
 00019043   1  --     CD    00    --   14  ---  PC: Acc. Grand Piano  
 00019045   1  --     BD    07    7F   14  ---  CC: Volume            
 00019045   1  --     BD    0A    40   14  ---  CC: PAN               
 00019045   1  --     BD    5D    00   14  ---  CC: Chorus Depth      
 00019045   1  --     BD    5B    00   14  ---  CC: Reverb Depth      
 00019045   1  --     BE    00    00   15  ---  CC: Bank MSB          
 00019045   1  --     BE    20    00   15  ---  CC: Bank LSB          
 00019045   1  --     CE    00    --   15  ---  PC: Acc. Grand Piano  
 00019045   1  --     BE    07    7F   15  ---  CC: Volume            
 00019045   1  --     BE    0A    40   15  ---  CC: PAN               
 00019045   1  --     BE    5D    00   15  ---  CC: Chorus Depth      
 00019045   1  --     BE    5B    00   15  ---  CC: Reverb Depth      
 00019045   1  --     BF    00    00   16  ---  CC: Bank MSB          
 00019045   1  --     BF    20    00   16  ---  CC: Bank LSB          
 00019045   1  --     CF    00    --   16  ---  PC: Acc. Grand Piano  
 00019045   1  --     BF    07    7F   16  ---  CC: Volume            
 00019045   1  --     BF    0A    40   16  ---  CC: PAN               
 00019048   1  --     BF    5D    00   16  ---  CC: Chorus Depth      
 00019048   1  --     BF    5B    00   16  ---  CC: Reverb Depth      
 00019059   1  --     B0    50    00    1  ---  Control Change        
 00019059   1  --     B0    51    00    1  ---  Control Change
As you can see, after all the Channels's CC#'s it will go back to Channel 1 and sends the SW1 and SW2 CC's. Don't be measlead by CC#80 and CC#81, I have some Combis that have different CC#.

So, it looks that I don't even have to use any Sysex at all. Which would lead to the next request:

How would I assign the CC# coming from the M3 to the Teensy after that Program Change to the SW1 and SW2 switches and check for it's value? (That's why I have that booleans there, because I will want to change the SW1 and SW2 colours according to the buttons state: On or Off).

P.S.: I will try by myself, but... ;)

I'll post my current sketch with Sysex experiments only in the next post.
 
It is not showing any CC data, only the Sysex result command, not the dump

Code:
// include the ResponsiveAnalogRead library for analog smoothing
#include <ResponsiveAnalogRead.h>
#include <Bounce.h>  // Bounce library makes button change detection easy
// ******CONSTANT VALUES******** - customize code behaviour here!


// SET THESE SIX VALUES FOR JOYSTICK!
const int pitchPin = 0; // PIN numbers ** MUST CHANGE!
const int modPin = 1;
const int modPin2 = 1;
const int pitchMaxRaw = 1019; // Max reading with full bend up... as raw 10-bit value
const int modMaxRaw = 1019; // Max reading full mod down


// SET THESE VALUES FOR RIBBON
//const int ribbonPin = touch_pressed; // Max reading on right side... as raw 10-bit value
const int ribbonMaxRaw = 474; // Max reading on right side... as raw 10-bit value
//


int Button1 = 0; //This is the default "Button Off" and 1 is "Button On"
int Button2 = 0; //This is the default "Button Off" and 1 is "Button On"
int OldButton1 = 0; //Variable to store button1 old value
int OldButton2 = 0; //Variable to store button2 old value
byte data1On[] = {0xf0, 0x42, 0x30, 0x75, 0x41, 0x00, 0x00, 0x01, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x01, 0xf7};
byte data1Off[] = {0xf0, 0x42, 0x30, 0x75, 0x41, 0x00, 0x00, 0x01, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf7};
byte data2On[] = {0xf0, 0x42, 0x30, 0x75, 0x41, 0x00, 0x00, 0x01, 0x00, 0x0B, 0x00, 0x00, 0x00, 0x00, 0x01, 0xf7};
byte data2Off[] = {0xf0, 0x42, 0x30, 0x75, 0x41, 0x00, 0x00, 0x01, 0x00, 0x0B, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf7};
byte progMode[] = {0xf0, 0x42, 0x30, 0x75, 0x4E, 0x02, 0xf7};
byte combiMode[] = {0xf0, 0x42, 0x30, 0x75, 0x4E, 0x00, 0xf7};
byte seqMode[] = {0xf0, 0x42, 0x30, 0x75, 0x4E, 0x04, 0xf7};
byte modeRequest[] = {0xF0, 0x42, 0x30, 0x75, 0x12, 0x00, 0xF7};
byte progRequest[] = {0xF0, 0x42, 0x30, 0x75, 0x74, 0x00, 0xF7};


const int channel = 1; // MIDI channel
const int MIDIdelay = 5; // will update MIDI only if this many milliseconds have passed
//******VARIABLES***********
// data variables and a lagged copy to compare before updating MIDI value
int pitch;
int mod;
int mod2;
int pitchRaw;
int modRaw;
int modRaw2;
int pitchLag;
int modLag;
int modLag2;
int ribbon;
int ribbonRaw;
int ribbonLag;


elapsedMillis pitchUpdate;
elapsedMillis modUpdate;
elapsedMillis modUpdate2;
elapsedMillis ribbonUpdate;


// ititialize the ReponsiveAnalogRead objects
ResponsiveAnalogRead readPitch = {pitchPin, true};
ResponsiveAnalogRead readMod = {modPin, true};
ResponsiveAnalogRead readMod2 = {modPin2, true};


#include <Adafruit_GFX.h>    // Core graphics library


#define LCD_ROTATION  1        //should work in all rotations
#define USE_READID    0        //Adafruit and ILI9488 can't read ID
//#include <MCUFRIEND_kbv.h>     // Hardware-specific library
//MCUFRIEND_kbv tft;
//#include <Adafruit_ILI9341.h>   // Hardware-specific library
//Adafruit_ILI9341 tft(10, 9, 8);
//#include <HX8347D_kbv.h>        // Hardware-specific library
//HX8347D_kbv tft;
#include <ILI9488.h>            // Hardware-specific library
ILI9488 tft(10, 9, 8);
//#include <ILI9488_kbv.h>            // Hardware-specific library
//ILI9488_kbv tft;


extern void Touch_initialise(int aspect, int wid, int ht);
extern bool Touch_getXY(void);
bool touch_pressed;
int pixel_x, pixel_y;
boolean SW1on = false;
boolean SW2on = false;
boolean Progon = false;
boolean Combion = false;
boolean Seqon = false;
boolean ribbonCtrl = false;


// Color definitions
#define TFT_BLACK       0x0000      /*   0,   0,   0 */
#define TFT_NAVY        0x000F      /*   0,   0, 128 */
#define TFT_DARKGREEN   0x03E0      /*   0, 128,   0 */
#define TFT_DARKCYAN    0x03EF      /*   0, 128, 128 */
#define TFT_MAROON      0x7800      /* 128,   0,   0 */
#define TFT_PURPLE      0x780F      /* 128,   0, 128 */
#define TFT_OLIVE       0x7BE0      /* 128, 128,   0 */
#define TFT_LIGHTGREY   0xC618      /* 192, 192, 192 */
#define TFT_DARKGREY    0x7BEF      /* 128, 128, 128 */
#define TFT_BLUE        0x001F      /*   0,   0, 255 */
#define TFT_GREEN       0x07E0      /*   0, 255,   0 */
#define TFT_CYAN        0x07FF      /*   0, 255, 255 */
#define TFT_RED         0xF800      /* 255,   0,   0 */
#define TFT_RED2        0xF88D      /* 254,  18, 106 */
#define TFT_MAGENTA     0xF81F      /* 255,   0, 255 */
#define TFT_YELLOW      0xFFE0      /* 255, 255,   0 */
#define TFT_WHITE       0xFFFF      /* 255, 255, 255 */
#define TFT_ORANGE      0xFD20      /* 255, 165,   0 */
#define TFT_ORANGE2     0xFB20      /* 254, 102,   1 */
#define TFT_GREENYELLOW 0xAFE5      /* 173, 255,  47 */
#define TFT_PINK        0xF81F


/******************* UI details */


#define PROGFRAME_X 20
#define PROGFRAME_Y 10
#define PROGFRAME_W 90
#define PROGFRAME_H 50


#define PROGBUTTON_X PROGFRAME_X
#define PROGBUTTON_Y PROGFRAME_Y
#define PROGBUTTON_W PROGFRAME_W
#define PROGBUTTON_H PROGFRAME_H


#define COMBIFRAME_X 200
#define COMBIFRAME_Y 10
#define COMBIFRAME_W 90
#define COMBIFRAME_H 50


#define COMBIBUTTON_X COMBIFRAME_X
#define COMBIBUTTON_Y COMBIFRAME_Y
#define COMBIBUTTON_W COMBIFRAME_W
#define COMBIBUTTON_H COMBIFRAME_H


#define SEQFRAME_X 370
#define SEQFRAME_Y 10
#define SEQFRAME_W 90
#define SEQFRAME_H 50


#define SEQBUTTON_X SEQFRAME_X
#define SEQBUTTON_Y SEQFRAME_Y
#define SEQBUTTON_W SEQFRAME_W
#define SEQBUTTON_H SEQFRAME_H


#define SW1FRAME_X 90
#define SW1FRAME_Y 110
#define SW1FRAME_W 130
#define SW1FRAME_H 70


#define SW1BUTTON_X SW1FRAME_X
#define SW1BUTTON_Y SW1FRAME_Y
#define SW1BUTTON_W SW1FRAME_W
#define SW1BUTTON_H SW1FRAME_H


#define SW2FRAME_X 310
#define SW2FRAME_Y 110
#define SW2FRAME_W 130
#define SW2FRAME_H 70


#define SW2BUTTON_X SW2FRAME_X
#define SW2BUTTON_Y SW2FRAME_Y
#define SW2BUTTON_W SW2FRAME_W
#define SW2BUTTON_H SW2FRAME_H


#define RIBBONFRAME_X 10
#define RIBBONFRAME_Y 240
#define RIBBONFRAME_W 470
#define RIBBONFRAME_H 70


#define RIBBON_X RIBBONFRAME_X
#define RIBBON_Y RIBBONFRAME_Y
#define RIBBON_W RIBBONFRAME_W
#define RIBBON_H RIBBONFRAME_H


void progBtn()
{ 
  tft.drawRect(PROGBUTTON_X, PROGBUTTON_Y, PROGBUTTON_W, PROGBUTTON_H, TFT_WHITE);
  tft.fillRect(PROGBUTTON_X, PROGBUTTON_Y, PROGBUTTON_W, PROGBUTTON_H, TFT_WHITE);
  tft.setCursor(40, 25);
  tft.setTextColor(TFT_BLACK);
  tft.setTextSize(2);
  tft.println("Prog");
  usbMIDI.sendSysEx(7, modeRequest, true); //The Sysex to change to Program Mode in Korg M3
  Progon = false;
}
void combiBtn()
{ 
  tft.drawRect(COMBIBUTTON_X, COMBIBUTTON_Y, COMBIBUTTON_W, COMBIBUTTON_H, TFT_WHITE);
  tft.fillRect(COMBIBUTTON_X, COMBIBUTTON_Y, COMBIBUTTON_W, COMBIBUTTON_H, TFT_WHITE);
  tft.setCursor(220, 25);
  tft.setTextColor(TFT_BLACK);
  tft.setTextSize(2);
  tft.println("Combi");
  usbMIDI.sendSysEx(7, combiMode, true); //The Sysex to change to Combi Mode in Korg M3
  Combion = false;
}
void seqBtn()
{ 
  tft.drawRect(SEQBUTTON_X, SEQBUTTON_Y, SEQBUTTON_W, SEQBUTTON_H, TFT_WHITE);
  tft.fillRect(SEQBUTTON_X, SEQBUTTON_Y, SEQBUTTON_W, SEQBUTTON_H, TFT_WHITE);
  tft.setCursor(400, 25);
  tft.setTextColor(TFT_BLACK);
  tft.setTextSize(2);
  tft.println("Seq");
  usbMIDI.sendSysEx(7, seqMode, true); //The Sysex to change to SEQ Mode in Korg M3
  Seqon = false;
}
void sw1Btn()
{ 
  tft.drawRect(SW1BUTTON_X, SW1BUTTON_Y, SW1BUTTON_W, SW1BUTTON_H, TFT_DARKGREY);
  tft.fillRect(SW1BUTTON_X, SW1BUTTON_Y, SW1BUTTON_W, SW1BUTTON_H, TFT_RED);
  tft.setCursor(160, 140);
  tft.setTextColor(TFT_WHITE);
  tft.setTextSize(2);
  tft.println("SW1");
  SW1on = false;
}
void sw2Btn()
{ 
  tft.drawRect(SW2BUTTON_X, SW2BUTTON_Y, SW2BUTTON_W, SW2BUTTON_H, TFT_DARKGREY);
  tft.fillRect(SW2BUTTON_X, SW2BUTTON_Y, SW2BUTTON_W, SW2BUTTON_H, TFT_RED);
  tft.setCursor(340,140);
  tft.setTextColor(TFT_WHITE);
  tft.setTextSize(2);
  tft.println("SW2");
  SW2on = false;
}
void rbCtrl()
{ 
  tft.drawRect(RIBBON_X, RIBBON_Y, RIBBON_W, RIBBON_H, TFT_LIGHTGREY);
  tft.fillRect(RIBBON_X, RIBBON_Y, RIBBON_W, RIBBON_H, TFT_LIGHTGREY);
  tft.setCursor(10,240);
    //remap to output data and send if changed and MIDIdelay has lapsed since last update for that parameter
    ribbon = map(pixel_x, 11, 474, 0, 127);
    ribbon = max(ribbon, 0); // need this now that the bottom isn't zero
    ribbon = min(ribbon, 127); // cap to avoid overflow
    if (abs(ribbon - ribbonLag) > 0 && ribbonUpdate > MIDIdelay ) {
      ribbonLag = ribbon;
    usbMIDI.sendControlChange(16, ribbon, channel);
      ribbonUpdate = 0;
    }
  ribbonCtrl = false;
}


int           sysExIndex=0;     // index for keeping track of incoming sysEx bytes


// handle incoming sysex messages 
// Copied from the midi controller project from Gerrit. 
//So, a Big Thank You to Gerrit from the pjrc forum https://forum.pjrc.com/members/47405-Gerrit


void handleSysEx(const byte* sysExData, uint16_t sysExSize, bool complete)
{
  // check if this is the start of the sysEx message
  if (sysExData[0]==240){
    sysExIndex=0;
  }
  Serial.print("The sysex length is ");
  Serial.print(sysExSize);
  Serial.print(" bytes\t");
  Serial.print("complete is\t");
  Serial.print(complete);
  Serial.println(); 
  for (int i=0;i<sysExSize;i++){
    sysExIndex++;
    Serial.print(sysExData[i],HEX);
    Serial.print(" ");
  }
  Serial.println(); 
  // message end
  if (complete && sysExData[sysExSize-1]==247){
   Serial.print("The total sysex message length is ");
   Serial.print(sysExIndex);
  Serial.print(" bytes");
  }
}


void setup(void)
{
    usbMIDI.setHandleSysEx(handleSysEx);
  uint16_t result;
  
    Serial.begin(9600);
    Serial.println(F("TFT LCD test"));


    tft.begin();


    int aspect = LCD_ROTATION;   //PORTRAIT
    tft.setRotation(aspect);
    Touch_initialise(aspect, tft.width(), tft.height());  //.kbv external function
    tft.fillScreen(TFT_BLACK);
    


    // create 'SW1 Switch'
    tft.drawRect(SW1BUTTON_X, SW1BUTTON_Y, SW1BUTTON_W, SW1BUTTON_H, TFT_DARKGREY);
    tft.fillRect(SW1BUTTON_X, SW1BUTTON_Y, SW1BUTTON_W, SW1BUTTON_H, TFT_RED);
    tft.setCursor(155, 140);
    tft.setTextColor(TFT_BLACK);
    tft.setTextSize(2);
    tft.print("SW1");


    // create 'SW2 Switch'
    tft.drawRect(SW2BUTTON_X, SW2BUTTON_Y, SW2BUTTON_W, SW2BUTTON_H, TFT_DARKGREY);
    tft.fillRect(SW2BUTTON_X, SW2BUTTON_Y, SW2BUTTON_W, SW2BUTTON_H, TFT_RED);
    tft.setCursor(340, 140);
    tft.setTextColor(TFT_BLACK);
    tft.setTextSize(2);
    tft.print("SW2");


    // create 'PROG Switch'
    tft.drawRect(PROGBUTTON_X, PROGBUTTON_Y, PROGBUTTON_W, PROGBUTTON_H, TFT_DARKGREY);
    tft.fillRect(PROGBUTTON_X, PROGBUTTON_Y, PROGBUTTON_W, PROGBUTTON_H, TFT_BLUE);
    tft.setCursor(40, 25);
    tft.setTextColor(TFT_BLACK);
    tft.setTextSize(2);
    tft.print("Prog");    


    // create 'COMBI Switch'
    tft.drawRect(COMBIBUTTON_X, COMBIBUTTON_Y, COMBIBUTTON_W, COMBIBUTTON_H, TFT_DARKGREY);
    tft.fillRect(COMBIBUTTON_X, COMBIBUTTON_Y, COMBIBUTTON_W, COMBIBUTTON_H, TFT_RED);
    tft.setCursor(220, 25);
    tft.setTextColor(TFT_BLACK);
    tft.setTextSize(2);
    tft.print("Combi");
     
    // create 'SEQ Switch'
    tft.drawRect(SEQBUTTON_X, SEQBUTTON_Y, SEQBUTTON_W, SEQBUTTON_H, TFT_DARKGREY);
    tft.fillRect(SEQBUTTON_X, SEQBUTTON_Y, SEQBUTTON_W, SEQBUTTON_H, TFT_YELLOW);
    tft.setCursor(400, 25);
    tft.setTextColor(TFT_BLACK);
    tft.setTextSize(2);
    tft.print("Seq");     


    // create 'Ribbon Emulator field'
    tft.drawRect(RIBBON_X, RIBBON_Y, RIBBON_W, RIBBON_H, TFT_DARKGREY);
    tft.fillRect(RIBBON_X, RIBBON_Y, RIBBON_W, RIBBON_H, TFT_LIGHTGREY);
}


void loop(void)
{


  usbMIDI.read();
  if (usbMIDI.read() == 1 && usbMIDI.getType() == 0xF0) 
  {//check for sysex 
   const byte korgdata1 = usbMIDI.getData1();
   const byte korgdata2 = usbMIDI.getData2();
   
   const byte *pSysExArray = usbMIDI.getSysExArray(); //capture data
   Serial.print(*pSysExArray);    
   Serial.print(korgdata1);    Serial.println(korgdata2);
  }
    int x = -1, y = -1;   //regular pixel coordinates
    touch_pressed = Touch_getXY();  //external function
#if 0
    Serial.print("X="); Serial.print(pixel_x); 
    Serial.print(" Y="); Serial.print(pixel_y); 
    Serial.print(" Z="); Serial.print(touch_pressed); 
    Serial.println("");
#endif
    if (touch_pressed) {
        x = pixel_x;      //copy global variable
        y = pixel_y;
    }


    {
      if((x > PROGBUTTON_X) && (x < (PROGBUTTON_X + PROGBUTTON_W))) {
        if ((y > PROGBUTTON_Y) && (y <= (PROGBUTTON_Y + PROGBUTTON_H))) {
          Serial.println("PROG btn hit"); 
          delay(100); // UI debouncing
          progBtn();
        }
      }
    }
{
      if((x > COMBIBUTTON_X) && (x < (COMBIBUTTON_X + COMBIBUTTON_W))) {
        if ((y > COMBIBUTTON_Y) && (y <= (COMBIBUTTON_Y + COMBIBUTTON_H))) {
          Serial.println("Combi btn hit"); 
          delay(100); // UI debouncing
          combiBtn();
        }
      }
    }
{
      if((x > SEQBUTTON_X) && (x < (SEQBUTTON_X + SEQBUTTON_W))) {
        if ((y > SEQBUTTON_Y) && (y <= (SEQBUTTON_Y + SEQBUTTON_H))) {
          Serial.println("Seq btn hit"); 
          delay(100); // UI debouncing
          seqBtn();
        }
      }
    }
    
{
      if((x > SW1BUTTON_X) && (x < (SW1BUTTON_X + SW1BUTTON_W))) {
        if ((y > SW1BUTTON_Y) && (y <= (SW1BUTTON_Y + SW1BUTTON_H))) {
          Serial.println("SW1 btn hit"); 
          delay(100); // UI debouncing
          sw1Btn();
        }
      }
    }


{
      if((x > SW2BUTTON_X) && (x < (SW2BUTTON_X + SW2BUTTON_W))) {
        if ((y > SW2BUTTON_Y) && (y <= (SW2BUTTON_Y + SW2BUTTON_H))) {
          Serial.println("SW2 btn hit"); 
          delay(100); // UI debouncing
          sw2Btn();
        }
      }
    } 
{
      if((x > RIBBON_X) && (x < (RIBBON_X + RIBBON_W))) {
        if ((y > RIBBON_Y) && (y <= (RIBBON_Y + RIBBON_H))) {
          Serial.println("Ribbon pressed"); 
          Serial.println(pixel_x);
          Serial.println(ribbon);       
          delay(100); // UI debouncing
          rbCtrl();
        }
      }
    } 
    
  }
 
With the code on the previous post i can only receive one cc message, that corresponds to the last message the synthesizer sends.
What can i do to receive all of them and then "choose" the ones to assign to the SW1 and SW2 switches?
 
With the code on the previous post i can only receive one cc message, that corresponds to the last message the synthesizer sends.
What can i do to receive all of them and then "choose" the ones to assign to the SW1 and SW2 switches?

First off I'm not sure your code makes sense
Code:
  usbMIDI.read();
  if (usbMIDI.read() == 1 && usbMIDI.getType() == 0xF0) 
  {//check for sysex 
   const byte korgdata1 = usbMIDI.getData1();
   const byte korgdata2 = usbMIDI.getData2();
   
   const byte *pSysExArray = usbMIDI.getSysExArray(); //capture data
   Serial.print(*pSysExArray);    
   Serial.print(korgdata1);    Serial.println(korgdata2);
  }
I believe this reads two messages; once without checking the result and once with.

The code
usbMIDI.read() == 1
reads the next message and is True if message read secuessfully.

Then you check variables that will have values from the last successful read of that type (sysex or all others).
But the D1 and D2 values are from the first read as the second read is sysex.

I would think the behavior is pretty random.

Checking result and type together is OK if you are filtering by type but if you mean to process both regular and sysex you need to check type after you read.. and there must be only one read per loop and then split the code by type.

You might prefer to use callback approach outlined https://www.pjrc.com/teensy/td_midi.html in the section: Receiving Messages with Read & Callback Functions


But I don't hear that you have a plan to find the right messages.
 
Hi oddson.
The sysex part are now commented out. It was part of the tests i was doing, didn't thing it could be influencing the result.
As i mentioned before, it was after starting this last segment of the controller that i noticed that the synth was sending the cc messages i needed, that's why i also have the other 3 buttons for Prog/Combi/Seq Modes. If this works they will not be needed too.

This is the sketch as it is at this very moment:

Code:
// include the ResponsiveAnalogRead library for analog smoothing
#include <ResponsiveAnalogRead.h>
#include <Bounce.h>  // Bounce library makes button change detection easy
// ******CONSTANT VALUES******** - customize code behaviour here!


// SET THESE SIX VALUES FOR JOYSTICK!
const int pitchPin = 0; // PIN numbers ** MUST CHANGE!
const int modPin = 1;
const int modPin2 = 1;
const int pitchMaxRaw = 1019; // Max reading with full bend up... as raw 10-bit value
const int modMaxRaw = 1019; // Max reading full mod down


// SET THESE VALUES FOR RIBBON
//const int ribbonPin = touch_pressed; // Max reading on right side... as raw 10-bit value
const int ribbonMaxRaw = 474; // Max reading on right side... as raw 10-bit value
//


int Button1 = 0; //This is the default "Button Off" and 1 is "Button On"
int Button2 = 0; //This is the default "Button Off" and 1 is "Button On"
int OldButton1 = 0; //Variable to store button1 old value
int OldButton2 = 0; //Variable to store button2 old value
byte data1On[] = {0xf0, 0x42, 0x30, 0x75, 0x41, 0x00, 0x00, 0x01, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x01, 0xf7};
byte data1Off[] = {0xf0, 0x42, 0x30, 0x75, 0x41, 0x00, 0x00, 0x01, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf7};
byte data2On[] = {0xf0, 0x42, 0x30, 0x75, 0x41, 0x00, 0x00, 0x01, 0x00, 0x0B, 0x00, 0x00, 0x00, 0x00, 0x01, 0xf7};
byte data2Off[] = {0xf0, 0x42, 0x30, 0x75, 0x41, 0x00, 0x00, 0x01, 0x00, 0x0B, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf7};
byte progMode[] = {0xf0, 0x42, 0x30, 0x75, 0x4E, 0x02, 0xf7};
byte combiMode[] = {0xf0, 0x42, 0x30, 0x75, 0x4E, 0x00, 0xf7};
byte seqMode[] = {0xf0, 0x42, 0x30, 0x75, 0x4E, 0x04, 0xf7};
byte modeRequest[] = {0xF0, 0x42, 0x30, 0x75, 0x12, 0x00, 0xF7};
byte progRequest[] = {0xF0, 0x42, 0x30, 0x75, 0x74, 0x00, 0xF7};


const int channel = 1; // MIDI channel
const int MIDIdelay = 5; // will update MIDI only if this many milliseconds have passed
//******VARIABLES***********
// data variables and a lagged copy to compare before updating MIDI value
int pitch;
int mod;
int mod2;
int pitchRaw;
int modRaw;
int modRaw2;
int pitchLag;
int modLag;
int modLag2;
int ribbon;
int ribbonRaw;
int ribbonLag;


elapsedMillis pitchUpdate;
elapsedMillis modUpdate;
elapsedMillis modUpdate2;
elapsedMillis ribbonUpdate;


// ititialize the ReponsiveAnalogRead objects
ResponsiveAnalogRead readPitch = {pitchPin, true};
ResponsiveAnalogRead readMod = {modPin, true};
ResponsiveAnalogRead readMod2 = {modPin2, true};


#include <Adafruit_GFX.h>    // Core graphics library


#define LCD_ROTATION  1        //should work in all rotations
#define USE_READID    0        //Adafruit and ILI9488 can't read ID
//#include <MCUFRIEND_kbv.h>     // Hardware-specific library
//MCUFRIEND_kbv tft;
//#include <Adafruit_ILI9341.h>   // Hardware-specific library
//Adafruit_ILI9341 tft(10, 9, 8);
//#include <HX8347D_kbv.h>        // Hardware-specific library
//HX8347D_kbv tft;
#include <ILI9488.h>            // Hardware-specific library
ILI9488 tft(10, 9, 8);
//#include <ILI9488_kbv.h>            // Hardware-specific library
//ILI9488_kbv tft;


extern void Touch_initialise(int aspect, int wid, int ht);
extern bool Touch_getXY(void);
bool touch_pressed;
int pixel_x, pixel_y;
boolean SW1on = false;
boolean SW2on = false;
boolean Progon = false;
boolean Combion = false;
boolean Seqon = false;
boolean ribbonCtrl = false;


// Color definitions
#define TFT_BLACK       0x0000      /*   0,   0,   0 */
#define TFT_NAVY        0x000F      /*   0,   0, 128 */
#define TFT_DARKGREEN   0x03E0      /*   0, 128,   0 */
#define TFT_DARKCYAN    0x03EF      /*   0, 128, 128 */
#define TFT_MAROON      0x7800      /* 128,   0,   0 */
#define TFT_PURPLE      0x780F      /* 128,   0, 128 */
#define TFT_OLIVE       0x7BE0      /* 128, 128,   0 */
#define TFT_LIGHTGREY   0xC618      /* 192, 192, 192 */
#define TFT_DARKGREY    0x7BEF      /* 128, 128, 128 */
#define TFT_BLUE        0x001F      /*   0,   0, 255 */
#define TFT_GREEN       0x07E0      /*   0, 255,   0 */
#define TFT_CYAN        0x07FF      /*   0, 255, 255 */
#define TFT_RED         0xF800      /* 255,   0,   0 */
#define TFT_RED2        0xF88D      /* 254,  18, 106 */
#define TFT_MAGENTA     0xF81F      /* 255,   0, 255 */
#define TFT_YELLOW      0xFFE0      /* 255, 255,   0 */
#define TFT_WHITE       0xFFFF      /* 255, 255, 255 */
#define TFT_ORANGE      0xFD20      /* 255, 165,   0 */
#define TFT_ORANGE2     0xFB20      /* 254, 102,   1 */
#define TFT_GREENYELLOW 0xAFE5      /* 173, 255,  47 */
#define TFT_PINK        0xF81F


/******************* UI details */


#define PROGFRAME_X 20
#define PROGFRAME_Y 10
#define PROGFRAME_W 90
#define PROGFRAME_H 50


#define PROGBUTTON_X PROGFRAME_X
#define PROGBUTTON_Y PROGFRAME_Y
#define PROGBUTTON_W PROGFRAME_W
#define PROGBUTTON_H PROGFRAME_H


#define COMBIFRAME_X 200
#define COMBIFRAME_Y 10
#define COMBIFRAME_W 90
#define COMBIFRAME_H 50


#define COMBIBUTTON_X COMBIFRAME_X
#define COMBIBUTTON_Y COMBIFRAME_Y
#define COMBIBUTTON_W COMBIFRAME_W
#define COMBIBUTTON_H COMBIFRAME_H


#define SEQFRAME_X 370
#define SEQFRAME_Y 10
#define SEQFRAME_W 90
#define SEQFRAME_H 50


#define SEQBUTTON_X SEQFRAME_X
#define SEQBUTTON_Y SEQFRAME_Y
#define SEQBUTTON_W SEQFRAME_W
#define SEQBUTTON_H SEQFRAME_H


#define SW1FRAME_X 90
#define SW1FRAME_Y 110
#define SW1FRAME_W 130
#define SW1FRAME_H 70


#define SW1BUTTON_X SW1FRAME_X
#define SW1BUTTON_Y SW1FRAME_Y
#define SW1BUTTON_W SW1FRAME_W
#define SW1BUTTON_H SW1FRAME_H


#define SW2FRAME_X 310
#define SW2FRAME_Y 110
#define SW2FRAME_W 130
#define SW2FRAME_H 70


#define SW2BUTTON_X SW2FRAME_X
#define SW2BUTTON_Y SW2FRAME_Y
#define SW2BUTTON_W SW2FRAME_W
#define SW2BUTTON_H SW2FRAME_H


#define RIBBONFRAME_X 10
#define RIBBONFRAME_Y 240
#define RIBBONFRAME_W 470
#define RIBBONFRAME_H 70


#define RIBBON_X RIBBONFRAME_X
#define RIBBON_Y RIBBONFRAME_Y
#define RIBBON_W RIBBONFRAME_W
#define RIBBON_H RIBBONFRAME_H


void progBtn()
{ 
  tft.drawRect(PROGBUTTON_X, PROGBUTTON_Y, PROGBUTTON_W, PROGBUTTON_H, TFT_WHITE);
  tft.fillRect(PROGBUTTON_X, PROGBUTTON_Y, PROGBUTTON_W, PROGBUTTON_H, TFT_WHITE);
  tft.setCursor(40, 25);
  tft.setTextColor(TFT_BLACK);
  tft.setTextSize(2);
  tft.println("Prog");
  usbMIDI.sendSysEx(7, modeRequest, true); //The Sysex to change to Program Mode in Korg M3
  Progon = false;
}
void combiBtn()
{ 
  tft.drawRect(COMBIBUTTON_X, COMBIBUTTON_Y, COMBIBUTTON_W, COMBIBUTTON_H, TFT_WHITE);
  tft.fillRect(COMBIBUTTON_X, COMBIBUTTON_Y, COMBIBUTTON_W, COMBIBUTTON_H, TFT_WHITE);
  tft.setCursor(220, 25);
  tft.setTextColor(TFT_BLACK);
  tft.setTextSize(2);
  tft.println("Combi");
  usbMIDI.sendSysEx(7, combiMode, true); //The Sysex to change to Combi Mode in Korg M3
  Combion = false;
}
void seqBtn()
{ 
  tft.drawRect(SEQBUTTON_X, SEQBUTTON_Y, SEQBUTTON_W, SEQBUTTON_H, TFT_WHITE);
  tft.fillRect(SEQBUTTON_X, SEQBUTTON_Y, SEQBUTTON_W, SEQBUTTON_H, TFT_WHITE);
  tft.setCursor(400, 25);
  tft.setTextColor(TFT_BLACK);
  tft.setTextSize(2);
  tft.println("Seq");
  usbMIDI.sendSysEx(7, seqMode, true); //The Sysex to change to SEQ Mode in Korg M3
  Seqon = false;
}
void sw1Btn()
{ 
  tft.drawRect(SW1BUTTON_X, SW1BUTTON_Y, SW1BUTTON_W, SW1BUTTON_H, TFT_DARKGREY);
  tft.fillRect(SW1BUTTON_X, SW1BUTTON_Y, SW1BUTTON_W, SW1BUTTON_H, TFT_RED);
  tft.setCursor(160, 140);
  tft.setTextColor(TFT_WHITE);
  tft.setTextSize(2);
  tft.println("SW1");
  SW1on = false;
}
void sw2Btn()
{ 
  tft.drawRect(SW2BUTTON_X, SW2BUTTON_Y, SW2BUTTON_W, SW2BUTTON_H, TFT_DARKGREY);
  tft.fillRect(SW2BUTTON_X, SW2BUTTON_Y, SW2BUTTON_W, SW2BUTTON_H, TFT_RED);
  tft.setCursor(340,140);
  tft.setTextColor(TFT_WHITE);
  tft.setTextSize(2);
  tft.println("SW2");
  SW2on = false;
}
void rbCtrl()
{ 
  tft.drawRect(RIBBON_X, RIBBON_Y, RIBBON_W, RIBBON_H, TFT_LIGHTGREY);
  tft.fillRect(RIBBON_X, RIBBON_Y, RIBBON_W, RIBBON_H, TFT_LIGHTGREY);
  tft.setCursor(10,240);
    //remap to output data and send if changed and MIDIdelay has lapsed since last update for that parameter
    ribbon = map(pixel_x, 11, 474, 0, 127);
    //ribbon = max(ribbon, 0); // need this now that the bottom isn't zero
   // ribbon = min(ribbon, 127); // cap to avoid overflow
   // if (abs(ribbon - ribbonLag) > 0 && ribbonUpdate > MIDIdelay ) {
   //   ribbonLag = ribbon;
    usbMIDI.sendControlChange(16, ribbon, channel);
   //   ribbonUpdate = 0;
  //  }
  ribbonCtrl = false;
}


//int           sysExIndex=0;     // index for keeping track of incoming sysEx bytes


// handle incoming sysex messages 
// Copied from the midi controller project from Gerrit. 
//So, a Big Thank You to Gerrit from the pjrc forum https://forum.pjrc.com/members/47405-Gerrit


//void handleSysEx(const byte* sysExData, uint16_t sysExSize, bool complete)
//{
  // check if this is the start of the sysEx message
//  if (sysExData[0]==240){
//  sysExIndex=0;
//  }
//  Serial.print("The sysex length is ");
//Serial.print(sysExSize);
//  Serial.print(" bytes\t");
//  Serial.print("complete is\t");
//  Serial.print(complete);
//  Serial.println(); 
//  for (int i=0;i<sysExSize;i++){
//sysExIndex++;
//    Serial.print(sysExData[i],HEX);
//  Serial.print(" ");
//  }
//  Serial.println(); 
  // message end
//  if (complete && sysExData[sysExSize-1]==247){
//   Serial.print("The total sysex message length is ");
//   Serial.print(sysExIndex);
//  Serial.print(" bytes");
//  }
//}


void setup(void)
{
//  usbMIDI.setHandleSysEx(handleSysEx);
//  uint16_t result;
  
    Serial.begin(9600);
    Serial.println(F("TFT LCD test"));


    tft.begin();


    int aspect = LCD_ROTATION;   //PORTRAIT
    tft.setRotation(aspect);
    Touch_initialise(aspect, tft.width(), tft.height());  //.kbv external function
    tft.fillScreen(TFT_BLACK);
    


    // create 'SW1 Switch'
    tft.drawRect(SW1BUTTON_X, SW1BUTTON_Y, SW1BUTTON_W, SW1BUTTON_H, TFT_DARKGREY);
    tft.fillRect(SW1BUTTON_X, SW1BUTTON_Y, SW1BUTTON_W, SW1BUTTON_H, TFT_RED);
    tft.setCursor(155, 140);
    tft.setTextColor(TFT_BLACK);
    tft.setTextSize(2);
    tft.print("SW1");


    // create 'SW2 Switch'
    tft.drawRect(SW2BUTTON_X, SW2BUTTON_Y, SW2BUTTON_W, SW2BUTTON_H, TFT_DARKGREY);
    tft.fillRect(SW2BUTTON_X, SW2BUTTON_Y, SW2BUTTON_W, SW2BUTTON_H, TFT_RED);
    tft.setCursor(340, 140);
    tft.setTextColor(TFT_BLACK);
    tft.setTextSize(2);
    tft.print("SW2");


    // create 'PROG Switch'
    tft.drawRect(PROGBUTTON_X, PROGBUTTON_Y, PROGBUTTON_W, PROGBUTTON_H, TFT_DARKGREY);
    tft.fillRect(PROGBUTTON_X, PROGBUTTON_Y, PROGBUTTON_W, PROGBUTTON_H, TFT_BLUE);
    tft.setCursor(40, 25);
    tft.setTextColor(TFT_BLACK);
    tft.setTextSize(2);
    tft.print("Prog");    


    // create 'COMBI Switch'
    tft.drawRect(COMBIBUTTON_X, COMBIBUTTON_Y, COMBIBUTTON_W, COMBIBUTTON_H, TFT_DARKGREY);
    tft.fillRect(COMBIBUTTON_X, COMBIBUTTON_Y, COMBIBUTTON_W, COMBIBUTTON_H, TFT_RED);
    tft.setCursor(220, 25);
    tft.setTextColor(TFT_BLACK);
    tft.setTextSize(2);
    tft.print("Combi");
     
    // create 'SEQ Switch'
    tft.drawRect(SEQBUTTON_X, SEQBUTTON_Y, SEQBUTTON_W, SEQBUTTON_H, TFT_DARKGREY);
    tft.fillRect(SEQBUTTON_X, SEQBUTTON_Y, SEQBUTTON_W, SEQBUTTON_H, TFT_YELLOW);
    tft.setCursor(400, 25);
    tft.setTextColor(TFT_BLACK);
    tft.setTextSize(2);
    tft.print("Seq");     


    // create 'Ribbon Emulator field'
    tft.drawRect(RIBBON_X, RIBBON_Y, RIBBON_W, RIBBON_H, TFT_DARKGREY);
    tft.fillRect(RIBBON_X, RIBBON_Y, RIBBON_W, RIBBON_H, TFT_LIGHTGREY);
}


void loop(void)
{


  usbMIDI.read();
  if (usbMIDI.read()==1 && usbMIDI.getType() == 0xB0) {//check for CC
   const byte korgdata1 = usbMIDI.getData1();   
   const byte korgdata2 = usbMIDI.getData2();
     Serial.print(korgdata1);Serial.print(" "); Serial.println(korgdata2);
    }


    int x = -1, y = -1;   //regular pixel coordinates
    touch_pressed = Touch_getXY();  //external function
#if 0
    Serial.print("X="); Serial.print(pixel_x); 
    Serial.print(" Y="); Serial.print(pixel_y); 
    Serial.print(" Z="); Serial.print(touch_pressed); 
    Serial.println("");
#endif
    if (touch_pressed) {
        x = pixel_x;      //copy global variable
        y = pixel_y;
    }


{
      if((x > PROGBUTTON_X) && (x < (PROGBUTTON_X + PROGBUTTON_W))) {
        if ((y > PROGBUTTON_Y) && (y <= (PROGBUTTON_Y + PROGBUTTON_H))) {
          Serial.println("PROG btn hit"); 
          delay(100); // UI debouncing
          progBtn();
        }
      }
    }
{
      if((x > COMBIBUTTON_X) && (x < (COMBIBUTTON_X + COMBIBUTTON_W))) {
        if ((y > COMBIBUTTON_Y) && (y <= (COMBIBUTTON_Y + COMBIBUTTON_H))) {
          Serial.println("Combi btn hit"); 
          delay(100); // UI debouncing
          combiBtn();
        }
      }
    }
{
      if((x > SEQBUTTON_X) && (x < (SEQBUTTON_X + SEQBUTTON_W))) {
        if ((y > SEQBUTTON_Y) && (y <= (SEQBUTTON_Y + SEQBUTTON_H))) {
          Serial.println("Seq btn hit"); 
          delay(100); // UI debouncing
          seqBtn();
        }
      }
    }
    
{
      if((x > SW1BUTTON_X) && (x < (SW1BUTTON_X + SW1BUTTON_W))) {
        if ((y > SW1BUTTON_Y) && (y <= (SW1BUTTON_Y + SW1BUTTON_H))) {
          Serial.println("SW1 btn hit"); 
          delay(100); // UI debouncing
          sw1Btn();
        }
      }
    }


{
      if((x > SW2BUTTON_X) && (x < (SW2BUTTON_X + SW2BUTTON_W))) {
        if ((y > SW2BUTTON_Y) && (y <= (SW2BUTTON_Y + SW2BUTTON_H))) {
          Serial.println("SW2 btn hit"); 
          delay(100); // UI debouncing
          sw2Btn();
        }
      }
    } 
{
      if((x > RIBBON_X) && (x < (RIBBON_X + RIBBON_W))) {
        if ((y > RIBBON_Y) && (y <= (RIBBON_Y + RIBBON_H))) {
          Serial.println("Ribbon pressed"); 
          Serial.println(pixel_x);
          Serial.println(ribbon);       
          delay(100); // UI debouncing
          rbCtrl();
        }
      }
    } 
    
  }


Can you please help me on this, please?
 
Oh, and about finding the right messages (I suppose you mean: choosing the first or the second one to assign to the sw's) , i don't really know how to achieve that at this moment.
 
If i have like this:

Code:
void loop(void)
{


  usbMIDI.read();
  if (usbMIDI.getType() == 0xB0) {//check for CC
   const byte korgdata1 = usbMIDI.getData1();   
   const byte korgdata2 = usbMIDI.getData2();
     Serial.print(korgdata1);Serial.print(" "); Serial.println(korgdata2);
    }

it keeps looping in the second cc line BUT, truth be told, it prints all the CC# ;)

Let's keep digging this thing!
 
Hey guys. I'm trying. ;)

So, I followed oddson's advice and went to the midi example Paul has in the mais page: https://www.pjrc.com/teensy/td_midi.html
I removed my previous code and put the one in the mentioned page, changing accordingly to usbMIDI what needed to be changed and I already have something usable in the serial monitor. It shows this after a Program Change directly in the synth:

Code:
inactivity)
Message, type=192, data = 89 0
Message, type=176, data = 80 0
Message, type=176, data = 81 0
(inactivity)

All I need is to get those 2 "type 176" (Control Change) AFTER the "type 192" (Program Change) one, and make them be called by a SW1 and/or SW2 press.
That is:
1 - SW1 switch should send a data1 (80 in the example) and data2 (0 in the example) whenever we press it (That is, corresponding to what in the example is the first "type 176" line after the "type 192") . After that i would need their state to be assigned in some variable so that i could know their present state and if i press the switch again it would then send said data1 (80) and data2 (x).

2 - SW2 would behave the same ONLY that it's data1 and data2 values should be the ones captured from that second "type 176" message after the already mentioned "ype 176" one.

How can i...?
 
My main difficulty at this moment is how to get the last AND the previous midi CC messages and then assign each of them to each one variable so that they can then be assigned to the switches?
I'm thinking that some king of count function will be in the way to the solution, but still not there, yet!
 
Status
Not open for further replies.
Back
Top