IR recieving ok , freezes after transmitting

hi,
i’m trying to build a project that recieve IR codes from remote controls, which identify 4 specific commands
(marked as RED,BLUE,GREEN,YELLOW), and upon recieving RED it should transmit a constatnt transmission.

the problem is that it can recieve without bugs, but after it transmit it doest recieve anymore.
i attached an example output (see image), from that point on no other input can be recieved.

CODE:

#include <IRremote.h>

int RECV_PIN = 2;
int flag = 0 ;
unsigned long int RED = 3205937430;
unsigned long int GREEN = 61353670;
unsigned long int YELLOW = 2684089140;
unsigned long int BLUE = 3781012030;
int i;

decode_results results;
 IRrecv irrecv(RECV_PIN);
 IRsend irsend;

void setup() {
  Serial.begin(9600);
  irrecv.enableIRIn();// Start the receiver
}

void loop() {
  unsigned long int n;
  flag = 0;
  
  if (irrecv.decode(&results)) {
    n = results.value;
    Serial.print(" recieved: ");
    Serial.print(n);
    Serial.print("              of type: ");
    Serial.print(results.decode_type);
    Serial.print("              num if bits: ");
    Serial.print(results.bits);
    if (n == RED) {Serial.print("                                       RED        ");  flag =  1;   }
    if (n == GREEN) {Serial.print("                                   GREEN        ");  flag =  2;}
    if (n == YELLOW) {Serial.print("                                 YELLOW        ");  flag =  3;}
    if (n == BLUE) {Serial.print("                                       BLUE        ");   flag =  4;}
    Serial.print("\a\n\n");
    
    //SPECIAL CASE:
      if (flag == 1) {
          for (int i = 0; i < 3; i++) {
          irsend.sendSony(0xa90,32);
          delay(100);
          Serial.println(" sent succesfully \n");
        }
      }
      
     // Receive the next value
     irrecv.resume();
  }
  
}

output example:

thx

Right !

Amazing problem... as far as I can tell, you did nothing wrong with the code, however...

http://forum.arduino.cc/index.php?topic=55520.0

is a big discussion about why sending and receiving don't go well together. Without turning the library code inside out it seems both sending and receiving use Timer 2, so they interfere. Hence, after sending, receiving doesn't work anymore. At the end of the discussion there seems to be a link to something working,.

I rewrote the library code to make it send and receive at the same time. However, my code is specifically for lasertag and doesn't recognize any protocols other than that anymore. My trick is using Timer 1 for receiving and Timer 2 for sending PWM IR. For receiving Ken uses a solid state machine, I adapted it so it can send from a buffer as well.

A common topic in this forum.

After every send with the IRremote library, you need to enable receiving again.
In other words, sending turns off receiving.

I will leave it up to you to figure out the actual command via google (---> IRremote blog or this forum).

I think adding

irrecv.enableIRIn();

after sending will do the trick.