Music Shield 2.0. and IRSendRev

How to control Music Shield using IRSendRev?
While shield plays music IR code doesn’t work
If I set debug flag in IRSendRev, then I see “ir get bad data!”.
If music stopped (press stop key on a shield), then I see normal decoded packets.
I think problem in the Interrupts, but I still can’t do it for work.

New research :slight_smile:

ISR(TIMER1_OVF_vect) //Timer1 Service
{
//fill vs1053
if (digitalRead(VS_DREQ) == 1 && playingState == PS_PLAY && cur_file.isOpen() && !fastforward)
{
byte readLen = 0;
readLen = cur_file.read(readBuf, READ_BUF_LEN); // - if delete this string then IR code work well. Or if READ_BUF_LEN set to 2 (for testing purpose) then IR code work almost well. I think problem in read from SD card
vs1053.writeData(readBuf, readLen);
if (readLen < READ_BUF_LEN)
{
vs1053.writeRegister(SPI_MODE, 0, SM_OUTOFWAV);
vs1053.sendZerosToVS10xx();
//report play done event here…
playingState = PS_POST_PLAY;
exit;
}
//sei();
}
//update
if (++timerloop >= 20)
{
player._hardtime_update();
timerloop = 0;
}
}

Problem solved.
First:

#define IRpin_PIN PIND //add this
#define IRpin 2 //and this in your sketch

Second:

ISR(TIMER_INTR_NAME)
{
//Serial.println(micros());
TIMER_RESET;

//uint8_t irdata = (uint8_t)digitalRead(irparams.recvpin);
uint8_t irdata = (uint8_t)(IRpin_PIN & (1 << IRpin)); //add this string in the IRSendRev.cpp

Third:

ISR(TIMER_INTR_NAME)
{
//Serial.println(micros());
TIMER_RESET;

//uint8_t irdata = (uint8_t)digitalRead(irparams.recvpin);
uint8_t irdata = (uint8_t)(IRpin_PIN & (1 << IRpin));
irparams.timer++; // One more 50us tick
if (irparams.rawlen >= RAWBUF) {
// Buffer overflow
irparams.rcvstate = STATE_STOP;
TIMSK1 = _BV(TOIE1); //add this string in the IRSendRev.cpp
}
switch(irparams.rcvstate) {
case STATE_IDLE: // In the middle of a gap
if (irdata == MARK) {
if (irparams.timer < GAP_TICKS) {
// Not big enough to be a gap.
irparams.timer = 0;
}
else {
// gap just ended, record duration and start recording transmission
TIMSK1=0; //and this string in the IRSendRev.cpp
irparams.rawlen = 0;
irparams.rawbuf[irparams.rawlen++] = irparams.timer;
irparams.timer = 0;
irparams.rcvstate = STATE_MARK;
}
}
break;

Fourth:

void IRSendRev::Clear() {
irparams.rcvstate = STATE_IDLE;
irparams.rawlen = 0;
TIMSK1 = _BV(TOIE1); //add this string in the IRSendRev.cpp
}

Solution:
When IR start receive data we disable Timer1 interrupt and enable this after transmission is end and decoded. I think we can use cli() and sei() too.