Detecting burst signals (8 and 16) using IR receiver

Hi,

I am doing Project using IR Sensor. I have a transmitter (38kHz) with sends 8bursts and 16bursts.
where I am using RedLed for 16bursts and GreenLed for 8bursts.

I am unable to succeed When I try to decode the Signal using Receiver. I am able to detect when I write a code for individual(either 8 or 16 bits) sequences. But, when I try to Combine it, the logic works fine only for 16bits by flashing RedLed and doesn't work for 8bits (both the leds are flashing).

I am unable to fix this error.

Please someone help me to fix this issue.

As a reference I attach the code for the detection of 8bursts.

Thank you.

Single_8_burst_detection.ino (1.26 KB)