[Closed] Fail When It Have Too Many IF, ELSE IF??

PROBLEM
I have the problem that the Serial Monitor is not functional (no incoming data or unknown result) when I provided too many if, else if (more than 3 if, else if **below code "misubishi() Function") . However,when I comment some of it out everythings work fine!

NOTE
I have already set Baud Rate @ 57600, also the same with Serial.Begin()
I have already test all if and else if statement work.
my board is Arduino Uno.
Binary sketch size: 14,478 bytes (of a 32,256 byte maximum).

EDIT
Added All Code in problem sketch. - 6/13/2014
Added Answer - 7/13/2014
Deleted Unnecessary Code...

ANWSER
This is a solution for my case, it's about use of memory (SRAM)
problem in mitsubishi() that I assign many unsigned int code[] and it over SRAM limit
use of PROGMEM instead

so, it is not about TOO Many If, else if .

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

misubishi() FUNCTION

void mitsubishi(char* data){
    
    int khz=38;
      
    if (strcmp((char*)msg,"off") == 0) 
    {
//      Serial.println("send -> OFF");
      unsigned int code[] = {3150,1550,999,999,999,1111,450,000,999,999,999,1200,999,999,999,1111,999,999,999,999,999,1111,999,1200,999,1200,999,000,999,1200,999,999,999,1111,999,1200,999,1200,999,000,999,999,999,999,999,999,999,1111,999,1200,999,999,999,1111,999,1200,999,999,999,999,999,1111,999,999,999,999,999,1111,450,000,999,999,999,1200,999,1111,999,999,999,1200,999,1111,999,1200,999,1111,450,1111,999,1200,999,000,450,1111,999,999,999,1111,450,000,999,999,999,999,999,999,999,1111,999,999,999,1200,999,999,999,1111,999,1200,999,1111,999,1200,999,1200,999,000,999,999,999,1200,999,999,999,000,999,999,999,999,999,999,999,1111,999,1200,999,999,999,999,999,1111,999,1200,999,1111,450,1111,999,999,000,1200,450,000,999,1200,999,999,999,000,450,000,999,999,999,1200,999,000,450,1111,999,1000};
      irsend.sendRaw(code,sizeof(code)/sizeof(int),khz);
    }
    else if (strcmp((char*)msg,"on/27") == 0)
    {
//      Serial.println("send -> ON, @ 27 degree");
      unsigned int code[] = {3200,1550,999,000,450,1111,450,000,450,000,999,1111,450,000,450,1111,999,000,450,000,450,1111,450,1111,999,1111,450,000,450,1111,999,000,450,1111,450,1111,999,1111,450,000,450,000,999,999,999,000,450,1111,450,1111,999,000,450,1111,450,1111,999,000,450,000,450,1111,999,999,999,000,450,1111,450,000,999,999,999,1111,450,1111,999,999,999,1111,450,1111,999,1111,450,1111,450,1111,999,1111,450,000,450,1111,999,000,450,1111,450,000,999,999,999,000,450,000,450,1111,999,999,999,1111,450,000,450,1111,999,1111,450,1111,999,1111,450,1111,999,1200,999,1111,450,1111,999,999,999,000,450,000,450,000,450,000,999,999,999,000,450,000,450,000,450,1111,999,1111,450,000,450,1111,999,000,450,1111,450,000,450,1100,450,000,450,000,450,1111,999,999,999,1111,450,000,450,1111,999,1000};
      irsend.sendRaw(code,sizeof(code)/sizeof(int),khz);   
    }
    else if (strcmp((char*)msg,"on/26") == 0)
    {
//      Serial.println("send -> ON, @ 26 degree");
      unsigned int code[] = {3150,1550,999,999,450,1111,999,000,450,000,450,1111,999,999,999,1111,999,999,999,999,999,1111,999,1200,999,1200,999,000,999,1200,999,999,999,1111,999,1200,450,1111,999,000,999,999,999,999,999,999,999,1111,450,1111,999,999,999,1111,450,1111,999,999,999,999,999,1111,450,000,450,000,999,1111,450,000,450,000,450,1111,999,1111,450,000,450,1111,999,1111,450,1111,999,1200,999,1111,450,1111,999,999,999,1111,450,000,450,1111,999,000,450,000,450,000,450,000,999,1111,450,000,450,1111,999,999,999,1111,450,1111,999,1111,450,1111,450,1111,999,1111,450,1111,999,1111,450,000,450,000,450,000,999,999,999,000,450,000,450,000,999,999,999,999,999,1111,999,1200,999,1111,999,999,999,1200,999,1111,999,999,999,1200,999,999,999,000,999,999,999,1200,999,999,999,000,999,1200,999,1000};
      irsend.sendRaw(code,sizeof(code)/sizeof(int),khz);   
    }
    else if (strcmp((char*)msg,"on/25") == 0)
    {
//      Serial.println("send -> ON, @ 25 degree");
      unsigned int code[] = {3200,1550,999,000,450,1111,450,000,999,999,999,1111,450,000,450,1111,999,000,450,000,450,1111,450,1100,450,1111,450,000,450,1100,450,000,450,1111,450,1100,450,1111,450,000,450,000,999,000,450,000,450,1111,450,1111,999,000,450,1111,450,1111,999,000,450,000,450,1111,999,999,999,000,999,1200,999,999,999,999,999,1111,999,1200,999,999,999,1111,999,1200,999,1111,450,1111,999,1200,999,1111,999,999,999,1200,999,000,999,1200,999,999,999,999,999,000,999,999,999,1200,999,999,999,1111,999,999,999,1200,999,1111,999,1200,999,1111,450,1111,999,1200,999,1111,450,1111,999,999,999,000,450,000,450,000,450,000,999,999,999,000,450,000,450,000,450,1111,999,1111,450,000,450,1111,999,1111,450,1111,999,999,999,1111,450,000,450,000,999,1200,999,000,450,000,450,000,450,1111,999,1000};
      irsend.sendRaw(code,sizeof(code)/sizeof(int),khz);   
    }
    else if (strcmp((char*)msg,"on/20") == 0)
    {
//      Serial.println("send -> ON, @ 20 degree");
      unsigned int code[] = {3200,1500,450,000,450,1111,450,000,999,000,450,1111,450,000,450,1100,450,000,450,000,450,1111,999,1111,450,1111,450,000,999,1111,450,000,450,1111,999,1111,450,1111,450,000,999,999,999,000,450,000,450,1111,999,1111,450,000,450,1111,999,1111,450,000,450,000,450,1111,999,000,450,000,450,1111,999,999,999,000,450,1111,450,1111,999,000,450,1111,999,1200,999,1111,999,1200,999,1111,450,1111,450,000,999,1111,450,000,450,1111,999,999,999,000,450,000,450,000,450,1111,999,000,450,1111,450,000,450,1100,450,1111,450,1111,999,1111,450,1111,450,1111,999,1111,450,1111,999,999,999,000,450,000,450,000,450,000,999,999,999,000,450,000,450,000,450,1100,450,1111,450,000,450,000,999,999,999,1111,450,1111,999,1111,450,000,450,000,450,1111,999,1111,450,1111,999,999,999,000,450,1000};
      irsend.sendRaw(code,sizeof(code)/sizeof(int),khz);   
    }
    else if (strcmp((char*)msg,"info") == 0)
    {
//      Serial.println("send -> Fetch Temperature Info.");
      steps();
      radio.startListening();
    }
    else
    {
//      Serial.println("send -> Nothings.");
    }
}

You have a bug with your code. Your problem is not with the serial monitor!. So post all of your code!

Mark

I have edited my question. Thank for your respond.

Please post your code as a single unit rather than in pieces.

Also, please point out the part that has all of the IF statements that are causing problems.

As @holmes4 said there is NO possibility that the problem lies in the serial moniotr and I don't understand how you thought there might be. There is no means for the serial monitor to know what code is on your Arduino.

...R

However,when I comment some of it out everythings work fine!

That makes it sound suspiciously like you have a problem with shortage of memory and you do have some large arrays of ints in the program.

void loop(void)
{
  
  //check for any incoming message
  if (radio.available()) 
  {
    bool done = false;
    while (!done)
    {
      // Fetch the payload, and see if this was the last one.
      done = radio.read(msg,sizeof(msg));
      
    }//end while
      
    Serial.println((char*) msg);
    
    mitsubishi((char*)msg);

  }//end if incomming radio
  
}//end loop

Start by sorting out the above code.

  1. That does radio.read return - I am sure it is not a boolean!,

  2. msg should be a char array not int - if your having to put in a lot of explicit casts something is worng

  3. Why are you using a while in side loop(), loop is just called over and over, the trick is to avoid using for/while in loop()

  4. do you real want to print just the last message?

  5. strings passed to print/println MUST be null terminated you will screw up printing if they are not!

Mark

This post (Multiple "else if" problem - Project Guidance - Arduino Forum) is a SOLUTION for me.

Exactly the same problem, it's about use of memory (SRAM)

Thank you for all. :slight_smile: