thanks a lot one more time and also sorry for my english...
I've solved my problem. It was the keyboard (m-audio keystudio25, I don't recomend it for sending midi messages to arduino!!!!).
First, it sends the byte 254 every few millis (call active sensing, for test the conexions).
Second, this controller (i don't know if it happens with every controller of m-audio), if I play to notes at the same time, it doesn't sends 6 bytes, it sends 5 bytes:
NOTE_ON, NOTE_1, VEL_1, NOTE_2, VEL_2.
And the same with note off, but with vel=0.
Third, if I play a fast note (down and up immediatly) it sends NOTE_ON, NOTE_1, VEL_1, NOTE_1, 0.
I haven't found it anywhere... then if anyone have this problem, i hope it helps. Its my code for read what was my arduino receiving from de midi conexion:
/* THIS CODE READ THE BYTES WE RECIEVE AND SHOW US WITH THE THREE LEDS 13,12,11 FOR UNDERSTANDING THE MIDI MESSAGES*/
int statusLed=13; //one
int statusLed2=12; //ten
int statusLed3=11; //hundred
byte incomingByte;
void setup() {
pinMode(statusLed,OUTPUT); // declare the LED's pin as output
pinMode(statusLed2,OUTPUT); // declare the LED's pin as output
pinMode(statusLed3,OUTPUT); // declare the LED's pin as output
Serial.begin(31250); //9600 for USB i 31250 for MIDI i 38400 for debugging
}
void loop () {
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();
comptador(incomingByte);
}
}
void comptador(int num){
if (num<0){
intermitent(30,3);
intermitent(30,3);
intermitent(30,3);
intermitent(30,3);
}else if (num==0){
intermitent(30,1);
intermitent(30,1);
intermitent(30,1);
intermitent(30,1);
}else{
while(num>=100){
num=num-100;
intermitent(200,3);
}
delay(200);
while(num>=10){
num=num-10;
intermitent(200,2);
}
delay(200);
while(num>=1){
num=num-1;
intermitent(200,1);
}
}
delay(300);
intermitent(20,4); //end of number
delay(500);
}
void intermitent(int temps,int led){
blink(HIGH,led);
delay(temps);
blink(LOW,led);
delay(temps);
}
void blink(byte valor, int nled){
switch (nled){
case 1:
digitalWrite(statusLed, valor);
break;
case 2:
digitalWrite(statusLed2, valor);
break;
case 3:
digitalWrite(statusLed3, valor);
break;
case 4:
digitalWrite(statusLed, valor);
digitalWrite(statusLed2, valor);
digitalWrite(statusLed3, valor);
break;
}