Question regarding Arduino Switch cases

Hi, I’m actually having this project that involves an IR LED and my arduino. The code is basically long because I use Switch cases to respond to a corresponding command.
I have more than 30 buttons that needs to respond, therefore I have around 37 cases which looks like this:

#include <IRremote.h>

IRsend irsend;
int Bytein = 0;
unsigned int volup[68] = {9050,4500,550,550,600,500,600,1650,600,500,600,550,600,500,600,550,550,550,600,1650,600,1650,550,550,600,1650,550,1700,550,1650,550,1700,550,1700,550,550,550,1700,550,550,600,550,550,550,550,550,600,550,550,550,550,1700,550,550,600,1650,550,1700,550,1700,550,1650,600,1650,600,1650,550};
unsigned int pageup[68] = {9050,4450,600,500,600,550,550,1700,550,550,600,500,600,550,550,550,600,500,600,1650,600,1650,600,500,600,1650,600,1650,550,1700,550,1650,600,1650,600,500,600,550,600,500,600,550,550,550,600,500,600,550,550,550,600,1650,600,1600,600,1650,600,1650,600,1650,600,1600,600,1650,600,1650,600};
unsigned int powerSharp[76] = {3900,1800,550,400,550,1300,550,400,550,1350,550,400,500,1400,500,450,500,1350,550,400,500,1400,500,450,500,1350,500,1400,500,450,500,1400,500,400,550,1350,500,1400,500,1400,500,1350,500,450,500,450,500,1400,500,1350,500,450,500,450,500,450,500,450,500,1350,550,400,500,450,500,450,500,1400,500,450,500,400,550,400,500};
unsigned int ion[76] = {3900,1800,550,400,550,1350,500,400,550,1350,550,400,500,1400,500,450,500,1400,500,400,550,1350,500,450,500,1400,500,1350,550,400,500,1400,500,450,500,1350,500,1400,500,1400,500,1350,550,400,500,450,500,1400,500,1350,550,400,550,400,500,450,500,450,500,1400,500,400,550,400,500,450,500,1400,500,450,500,450,500,450,500};
unsigned int powerGeneral[76] = {3400,1550,450,350,500,300,500,1150,500,300,500,1150,450,400,450,350,450,350,450,1200,450,1200,450,350,450,350,450,400,450,1150,450,1200,450,350,450,400,450,350,450,350,450,400,450,350,450,350,450,400,450,350,450,350,450,400,450,350,450,350,450,1200,450,350,500,350,450,350,450,400,450,350,450,350,450,400,450};


unsigned int powerSamsung[68] = {4650,4350,700,1500,700,1550,700,1500,700,450,650,450,650,450,650,450,700,400,650,1600,650,1550,650,1600,650,450,650,500,600,500,650,450,650,500,600,500,600,1600,650,500,600,500,600,500,600,500,650,500,600,500,600,1600,650,450,650,1600,600,1600,650,1600,600,1600,650,1600,600,1600,650};
void setup() {                
  Serial.begin(9600); 
  //pinMode(13, OUTPUT);     
}
void loop() {
if (Serial.available() > 0) {
Bytein = Serial.read();
switch(Bytein){
case 0:
//digitalWrite(13,LOW);
break;  
case 1:
//digitalWrite(13, HIGH);   
Serial.println("1");
break;
case 2:
  irsend.sendRaw(powerLG,68,38); 
      delay(500);
      irsend.sendRaw(powerToshiba,68,38);
      delay(500);
      irsend.sendRaw(powerTelkom,68,38);
      delay(500);
      irsend.sendRaw(powerSharp,76,38);
      delay(500);
      irsend.sendRaw(powerGeneral,76,38);
      delay(500);
break;
case 3:
irsend.sendRaw(powerLG,68,38);
  delay(500);
  irsend.sendRaw(powerToshiba,68,38);
  delay(500);
  irsend.sendRaw(powerTelkom,68,38);
break;

case 4:
  irsend.sendRaw(powerSharp,76,38);
  delay(500);
  irsend.sendRaw(powerGeneral,76,38);
  delay(500);
break;

case 5:
irsend.sendRaw(volup,68,38);
break;

case 6:
  irsend.sendRaw(pageup,68,38);
break;

case 7:
irsend.sendRaw(muteLG,68,38);
break;

case 8:
 irsend.sendRaw(voldown,68,38);
break;

case 9:
irsend.sendRaw(pagedown,68,38);
break;

case 10:
  irsend.sendRaw(powerLG,68,38);
break;

case 11:
irsend.sendRaw(powerToshiba,68,38);
break;

case 12:
  irsend.sendRaw(up,68,38);
break;

case 13:
irsend.sendRaw(left,68,38);
break;

case 14:
  irsend.sendRaw(enter,68,38);  
  Serial.println("0");
break;

case 15:
irsend.sendRaw(right,68,38);   
Serial.println("1");
break;

case 16:
  irsend.sendRaw(down,68,38);
break;

case 17:
irsend.sendRaw(powerTelkom,68,38);
break;

case 18:
  irsend.sendRaw(mute,68,38);
break;

case 19:
irsend.sendRaw(one,68,38);
break;

case 20:
  irsend.sendRaw(two,68,38);
break;

case 21:
irsend.sendRaw(three,68,38);
break;

case 22:
  irsend.sendRaw(four,68,38);
break;

case 23:
irsend.sendRaw(five,68,38);
break;

case 24:
  irsend.sendRaw(six,68,38);
break;

case 25:
irsend.sendRaw(seven,68,38);
break;

case 26:
  irsend.sendRaw(eight,68,38);
break;

case 27:
irsend.sendRaw(nine,68,38);
break;

case 28:
 irsend.sendRaw(zero,68,38);
break;

case 29:
irsend.sendRaw(tvradio,68,38);
break;

case 30:
  irsend.sendRaw(pr,68,38);
break;

case 31:
 irsend.sendRaw(menu,68,38);
break;

case 32:
  irsend.sendRaw(upup,68,38);
break;

case 33:
irsend.sendRaw(exitt,68,38);
break;

case 34:
  irsend.sendRaw(downdown,68,38);
break;

case 35:
 irsend.sendRaw(powerSharp,76,38);
break;

case 36:
  irsend.sendRaw(ion,76,38);
break;

case 37:
  irsend.sendRaw(powerGeneral,76,38);
break;

case 38:
  irsend.sendRaw(powerGeneral,68,38);
break;

default :
break;

}
//
//
}

}

The problem is here and it’s quite interesting.
My Arduino actually receives the command(The RX led in arduino blinks in every button pressed) but the IR LED doesn’t work ( I use my camera app to check whether my IR LED lights up when I press the button or not).
And… when I uncode from case 27 to the rest. The IR LED lights up!
I’m wondering if Arduino can only handle 27 cases or not. Exactly 27 not more or else the IR LED just won’t light up, but still the RX led blinks.
By the way, the size of the file is less than 32kb.
Any solution?

Thanks guys :slight_smile:

i don't know if this will have any effect, but try to make your arrays const, like this:

const unsigned int volup[68] = {9050,4500,550,550,600,500,600,1650,600,500,600,550,600,500,600,550,550,550,600,...};

this consumes no RAM, and this might be the reason to your problem (i'm really not sure about it, but you can always try it )

this consumes no RAM,

Really?

I'd either factor them so they'll fit in bytes or put them in PROGMEM.

I don’t see anything in the code that would be affected by the mere presence of the extra switch cases (i.e. just having them in the code, not executing them). It would move the code around and might affect what variables are stored where which could expose memory related issues.

I haven’t figured out what all those big arrays are used for, but at the very least you should make them consts. Are you certain that you aren’t accessing beyond the bounds of any of those arrays?

Do you actually need them all? How much RAM does your sketch have free at runtime?

I haven’t spotted how your irsend object works either - does it need any sort of configuration/initialisation?