delay 5s when communicate serial port to transmit IR.

My project is control helicopter by kinect (processing), first time, i try to transmit IR for motor board . When i post a symbol to IR transmiter board, i see it delay 5s.
But, i used Serial Monitor to send a symbol and it has no delay.
then i use kinect to send the symbol to control motor board and it has no delay.
I think the problem on my IR transmiter code.
Please help me and thank you.
This is my code:
arduino ir transmiter

#define RED 4      
#define led 7
int incomingByte = 0;
int throttleCmd = 0;
char cmd;
void setup() {
Serial.begin(9600);
pinMode(RED, OUTPUT);
pinMode(led, OUTPUT);
}

void loop() {
 if (Serial.available()) {
  cmd = Serial.read();
  
  
 //===================================     IF ================================= 
  if (cmd == 'a')  {digitalWrite(led,HIGH);Transmit(10);}
 else if (cmd == 'b')  {digitalWrite(led,LOW);Transmit(20);}
 else if (cmd == 'c')  {digitalWrite(led,HIGH);Transmit(30);}
 else if (cmd == 'd')  {digitalWrite(led,LOW);Transmit(40);}
 }

  

  }


void Transmit(byte rudder) {
static byte Code[1];
byte mask = 128;         //bitmask
int i;

Code[0] = rudder; // 0 -> 127; 63 is the midpoint.


OutPulse(2002);  // Start 38Khz pulse for 2000us (2002us is evenly divided by 26) 
delayMicroseconds(2000);  // 2000us off.

                    // Loops through the Code[i] 
for (mask = 128; mask > 0; mask >>=1) {         // See Arduino reference for bit masking (really cool stuff!) 
OutPulse(312);                     // Sends 312 pulse each loop

if(Code[0] & mask) {          //If both bit positions are 1 you get 1             
delayMicroseconds(688);     // send 1 (700 off)
} 
else {
delayMicroseconds(288);     // send 0 (300 off)
}
} //End mask loop


OutPulse(312);  //Send 300 microsecond Closing Pulse 
delay(60);       

} // End Transmit 
void OutPulse(int Pulse) {  //sends 38Khz pulses over the Pulse Length 
int p;

for(p = 0; p < (Pulse / 26) - 1; p++) {  //Takes about 26 microseconds per loop
digitalWrite(RED, HIGH);
delayMicroseconds(10);
digitalWrite(RED, LOW);
delayMicroseconds(10);
}
}  //End OutPulse

You have 4 seconds delay in your code - might that be the problem?

This Thread may be of interest.

...R

thank you, ít's helpful :) :) :) :)