Sending IR codes program causing some trouble

Hi guys
I've been struggling with this problem few weeks now. Decided to try and get some help here. Hopw You have some ideas for me.

I'm trying to build a remote controls. It has 5 buttons:
4 buttons sending 4 different IR codes (via IR led of course)
The other button is shifting the codes. I mean - pressing the 5th with one of the 4 buttons will send different codes. I get 8 codes with 5 buttons.

Now, while I program (just to try) 5 codes - each for every button- Everything works wonderful. All is well.
When I try to program my real program - Some of the codes getting scrambled. I mean - some works just fine, but some send codes that make no sense.

Can anyone think of what can cause the problem?

#include <IRremote.h>
IRsend irsend;

#define CTRL     7     //blue
#define Up      12  //orange 
#define Down    11  //purple 
#define Next    9   //Green  
#define Last    10  //Yellow 

// setup the arrays for each code 
unsigned int VolUp[135] = {
8400, 4140 , 580 ,1500 , 580 ,460 , 600 ,1500 , 580 ,1500 , 580 ,480 , 580 ,1500 , 580 ,460 , 580 ,1500 , 580 ,480 , 580 ,
1500 ,
I cut it here....you get the idea...

}; //total 135

unsigned int VolDown[135] = {
***I cut it here for the forum, because the codes are long and doesn't matter
}; //total 135

unsigned int NextTrack[135] = {
***
}; //total 

unsigned int LastTrack[271] = {
***
}; //total 135

unsigned int NextFolder[135] = {
***
}; //total 135

unsigned int LastFolder[135] = {
***
}; //total 135

unsigned int Answer[135] = {    
***
}; //total 135

unsigned int EndCall[135] = {    
***
}; //total 135

void setup()
{
 pinMode(CTRL, INPUT); 
 pinMode(Up, INPUT); 
 pinMode(Down, INPUT); 
 pinMode(Next, INPUT); 
 pinMode(Last, INPUT); 

}

void loop()
{
    if (digitalRead(Up) == LOW){            //Up is pressed
    if (digitalRead(CTRL) == HIGH){         //CTRL is not pressed
        irsend.sendRaw(VolUp,135,38);       //Volume Up
        delay (200);
      }
    if (digitalRead(CTRL) == LOW){          //CTRL is pressed
        irsend.sendRaw(Answer,135,38);      //Answer
        delay(200);
      }
    }
    
 
    if (digitalRead(Down) == LOW){          //Down is pressed
       if (digitalRead(CTRL) == HIGH){      //CTRL is not pressed
         irsend.sendRaw(VolDown,135,38);    //Volume Down
         delay (200);
      }
    if (digitalRead(CTRL) == LOW){          //CTRL is pressed
        irsend.sendRaw(EndCall,135,38);     //End Call
        delay (200);
    }
    }
  
  
    if (digitalRead(Next) == LOW){          //Next is pressed
       if (digitalRead(CTRL) == HIGH){      //CTRL is not pressed
         irsend.sendRaw(NextTrack,135,38);  //Next Track
         delay (200);
      }
    if (digitalRead(CTRL) == LOW){          //CTRL is pressed
        irsend.sendRaw(NextFolder,135,38);  //Next Folder
        delay (200);
    }
    }
  
    if (digitalRead(Last) == LOW){          //Last is pressed
       if (digitalRead(CTRL) == HIGH){      //CTRL is not pressed
         irsend.sendRaw(LastTrack,135,38);  //Last Track
         delay (200);
      }
    if (digitalRead(CTRL) == LOW){          //CTRL is pressed
        irsend.sendRaw(LastFolder,135,38);  //Last Folder
        delay (200);
    }
    }
 
   }

Which Arduino board are you using ?
How many bytes do those arrays take up ?

Arduinio Uno
7 arrays are 135 long. and one of them is 271
all unsigned int.

Maybe I overflowed the memory?

2432 bytes of SRAM for your arrays only.
Your UNO only has 2K

.

I've been programming for years (as a hobby) and it's the first time I reach the memory limit.
Didn't think about it.
Thanks a lot! :slight_smile:

Get a Bobuino2, it has 16K of SRAM.

.

For sure :slight_smile:
http://www.crossroadsfencing.com/BobuinoRev17/


or

available with USB on board also.
or

Hey, it's 1/4 after midnight :sleeping:

Nice! This Bobuino is pretty neat!
But the arduino is enough for me for now :slight_smile:

Each array sends the IR code twice. "Just to be sure".
Didn't think it as a problem so far.
I've cut the arrays in half and it's working very well.
Maybe I'll send each array twice to be sure, but that's less important for now.

Thanks guys for the advice

You can put the arrays in flash memory too if they do not change.
Some version of this is used I think:

const unsigned int PROGMEM arrayName[] = { ... };