Go Down

Topic: Serial/MIDI problem (Read 586 times) previous topic - next topic

frax

I have a fairly big MIDI converter program that doesn't work quite right.
This stripped down code has the same problem:
Code: [Select]

int ledPin =  13;
int trigger = 3;

void setup()   {                
 pinMode(ledPin, OUTPUT);
 pinMode(trigger, OUTPUT);

 digitalWrite(trigger, HIGH);

 // Serial port as MIDI
 Serial.begin(31250);
}

void loop()                    
{
 while (Serial.available() > 0)
 {
   byte in = Serial.read();
 
   if (in == 0x90)  // 90 = keydown midi channel 1
   {    
     doTrigger();
   }
 }
}

void doTrigger()
{
 digitalWrite(ledPin, HIGH);
 digitalWrite(trigger, LOW);
 delay(1);
 digitalWrite(ledPin, LOW);
 digitalWrite(trigger, HIGH);
}


Wait for a key down and the just flip the pin and the LED for 1ms.

It works IF I hit the keys on my MIDI keyboard fairly slow to normal, speeding it up just a little, not anywhere near fast, it doesn't trigger.

I looked at the MIDI sent in a MIDI-monitor, nothing strange there.

Any suggestions?

/frax

Martin Gerken

BTW: you will not see the LED blink if it's ON for only 1 ms. (sorry, no idea for your primary problem)

frax

I actually see the LED flash, and the trigger is connected to my Synth so I can also hear when it's working.

MikMo

Are you sure you are not sending a lot of other information from the MIDI keyboard?, like polyphonic aftertouch, and all that stuff, so you are flooding your serial connection ?

Just a shot in the dark .-)

frax

#4
Jul 02, 2010, 05:20 pm Last Edit: Jul 02, 2010, 05:21 pm by frax Reason: 1
No aftertouch but my keyboard sends out a 0xfe (Active sense) frequently, i'd say about 4 each second.
I still think there would be plenty of time to receive and process midi messages without loosing any key downs.

frax

Im out of ideas, anyone?

Go Up