Arduino uno midi system exclusive

hi everyone, I have a project in progress, partly I have succeeded, my project is about sending SysEx midi message from Arduino Uno to my keyboard with a button and an LED and it works, but I want that if I press the button that does the same service on the kyeboard that send back the same message to the Arduino then the LED should light up or off .
the messages 23 bytes as follows:
F0 42 7F 60 01 01 10 7D 00 4E 00 00 00 00 00 00 00 00 00 00 00 00 F7
F0 42 7F 60 01 01 00 7D 00 00 00 00 00 00 00 00 00 00 00 00 00 00 F7
F0 42 7F 60 01 01 08 7D 00 00 4E 00 00 00 00 00 00 00 00 00 00 00 F7
F0 42 7F 60 01 01 00 7D 00 00 00 00 00 00 00 00 00 00 00 00 00 00 F7
Here is my code:

#include <MIDI.h>
#include <midi_Defs.h>
#include <midi_Message.h>
#include <midi_Namespace.h>
#include <midi_Settings.h>

static const unsigned SysExMaxSize = 256;
MIDI_CREATE_INSTANCE(HardwareSerial,Serial, midiOut); // create a MIDI object called midiOut
byte Coff[21] = {0x42,0x7F,0x60,0x01,0x01,0x10,0x7D,0x00,0x4E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
byte Con[21] = {0x42,0x7F,0x60,0x01,0x01,0x00,0x7D,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

int led = 13;
int button = 12;
int ledState = HIGH;
int buttonCurrent;
int buttonPrevious = LOW;



void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
  Serial.begin(31250);
 
 

  pinMode(button, INPUT);
  pinMode(led, OUTPUT);
  
  
}

void loop()


{
 buttonCurrent = digitalRead(button);
 
 if (buttonCurrent == HIGH && buttonPrevious == LOW)
 {
  if (ledState == HIGH)
  {
    ledState = LOW;

 midiOut.sendSysEx(21,Con, false);
  
  }
  else
  {
    ledState = HIGH;
 
 midiOut.sendSysEx(21,Coff, false);  
     }
   }
   digitalWrite(led, ledState);
   buttonPrevious = buttonCurrent;
     
    }

 

        


  

Your sketch is small enough to post inline, which is the forum norm.

Ok where should I move it?

Please see How to get the best out of this forum.

1 Like

You'll have to clarify this. Please explain which buttons and LEDs there are (connected to Arduino or on your keyboard), which MIDI messages are sent by each device and when, etc.

I send the SysEx message via pressing the button, which is connected to the Arduino pin 12, and at the same time the LED lights up which is connected to the pin 13, and with "midiOut.sendSysEx (21, Con, false);" messages are sent.
and it works and my keyboard responds, but I have a button on my keyboard and I want to when I press the button who sends the same message back to the Arduino that the LED lights up or goes off ..
I tried with getSysEx arry, but i can't compare the message to get the LED lights or off.
I use Arduino Uno and dualMoco ..

What have you tried? The MIDI library you're using should come with examples demonstrating how to handle MIDI input.

DualMoco is poorly designed and drops incoming SysEx messages if too much data is sent at a time, so you might want to use different firmware like USBMidiKlik.

MIDI_CREATE_INSTANCE(HardwareSerial,Serial, midiIn); // create a MIDI object called midiIn
and
sysex = midiIn.getSysExMessage()
and it worked for the Midi messages in and out, but how can i do some equation to get the led light on and off depending on the type off message?
Sorry about my english, and im new on Arduino...

Use handleSystemExclusive(byte* array, unsigned size), see the documentation for details. Then just check the size and access the bytes in the byte array you need. Based on those values, decide whether you need to turn on/off the LED.

1 Like

can you just send me some more information about it, I can not find enough ducoment about handleSystemExclusive.
Thanks
best regard

I have tried, either I can not handle it or it does not working for me:(

Post your best attempt. Did you try the firmware I recommended?

no because dual Moco.hex works perfectly with my keyboard, but any way, I can first test the firmware you recommend, where can I download that Hex file please?
Thanks

DualMoco has a bug where it overwrites its own buffer if you send more than 64 bytes over USB at a time, which might be a reason why your code doesn't work.

where can I download that Hex file please?

1 Like

I have tried with this firmware, but unfortunately it does not work with my keyboard .. :frowning:

Then it's time to post your code.

I can load SysEx message with midi.getSysEx of course, and the difference between my messages is between a few bytes, then the question is how can you take a comparison between them, so simple result will be instruction to turn on LED or turn off?
tak a look:
C: ON: F0 42 7F 60 01 01 10 7D 00 4E 00 00 00 00 00 00 00 00 00 00 00 00 F7
OFF: F0 42 7F 60 01 01 00 7D 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 F7

C #: ON: F0 42 7F 60 01 01 08 7D 00 00 4E 00 00 00 00 00 00 00 00 00 00 00 00 F7
OFF: F0 42 7F 60 01 01 00 7D 00 00 00 00 00 00 00 00 00 00 00 00 00 00 F7

D: ON: F0 42 7F 60 01 01 04 7D 00 00 00 4E 00 00 00 00 00 00 00 00 00 00 F7
OFF: F0 42 7F 60 01 01 00 7D 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 F7

Eb: ON: F0 42 7F 60 01 01 02 7D 00 00 00 00 4E 00 00 00 00 00 00 00 00 00 F7
OFF: F0 42 7F 60 01 01 00 7D 00 00 00 00 00 00 00 00 00 00 00 00 00 00 F7

E: ON: F0 42 7F 60 01 01 01 7D 00 00 00 00 00 4E 00 00 00 00 00 00 00 00 F7
OFF: F0 42 7F 60 01 01 00 7D 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 F7
............