After some days working and searching Google, i wrote this code which is working good on pc by sending the message through the serial monitor, but still not working on my keyboard...![]()
#include <MIDI.h>
#include <midi_Defs.h>
#include <midi_Message.h>
#include <midi_Namespace.h>
#include <midi_Settings.h>
#define MIDI_SYSEX_ARRAY_SIZE 255
static const unsigned SysExMaxSize = 256;
MIDI_CREATE_INSTANCE(HardwareSerial,Serial, MIDI);
const unsigned int MAX_MESSAGE_LENGTH = 69;
uint8_t Con[23] ={0x42,0x7F,0x60,0x01,0x01,0x10,0x7D,0x00,0x4E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
String C1= "F0 42 7F 60 01 01 10 7D 00 4E 00 00 00 00 00 00 00 00 00 00 00 00 F7";
String off="F0 42 7F 60 01 01 00 7D 00 00 00 00 00 00 00 00 00 00 00 00 00 00 F7";
int led = 13;
int ledState = LOW;
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
pinMode(led, OUTPUT);
Serial.begin(9600);
}
void loop() {
//Check to see if anything is available in the serial receive buffer
while (Serial.available() > 0)
{
//Create a place to hold the incoming message
static char message[MAX_MESSAGE_LENGTH];
static unsigned int message_pos = 0;
//Read the next available byte in the serial receive buffer
char inByte = Serial.read();
int S = MIDI.getSysExArray();
char X = MIDI.getSysExArray();
byte Z = MIDI.getSysExArray();
//Message coming in (check not terminating character) and guard for over message size
if ( inByte != '\n' && (message_pos < MAX_MESSAGE_LENGTH - 1) )
{
//Add the incoming byte to our message
message[message_pos] = inByte;
message_pos++;
}
//Full message received...
else
{
//Add null character to string
message[message_pos] = '\0';
String Y = message;
//Print the message (or do other things)
if (Y == off && ledState == HIGH)
{
ledState = LOW;}
if (Y == C1 && ledState == LOW)
{
ledState = HIGH;}
//Reset for the next message
message_pos = 0;
Serial.println(S);
Serial.println(X);
Serial.println(Z);
Serial.println(Y);
Serial.println(message);
}
}
digitalWrite(led, ledState);
}