Limit of if.

Hi

Im currently working on a program for my master and I got a problem.
I did this code and it was working :

int miseajour() //function Downlaod
{
    int i=0;
   
      if (imgs==60 && resol=="1024/1024")
      {
        if (time==1)
        {
           count=" 50."; 
           temps=5;
        }
        else if (time==2) 
        {
           count=" 51."; 
           temps=6;
        }
        else if (time==5) 
        {
           count=" 52."; 
           temps=9;
        }
        else if (time==10)
        {
           count=" 53."; 
           temps=14;
        }
      }
      if (imgs==60 && resol=="1024/768")
      {
        if (time==1)
        {
           count=" 65."; 
           temps=5;
        }
        else if (time==2) 
        {
           count=" 66."; 
           temps=6;
        }
        else if (time==5) 
        {
           count=" 67."; 
           temps=9;
        }
        else if (time==10)
        {
           count=" 68."; 
           temps=14;
        }

      }
      if (imgs==60 && resol=="768/768")
      {
       count=" 85."; 
       temps=85;
      }
      if (imgs==60 && resol=="512/512")
      {
       count=" 190."; 
       temps=190;
      }
      if (imgs==125 && resol=="1024/1024")
      {
       count=" 25."; 
       temps=25;
      }
      if (imgs==125 && resol=="1024/768")
      {
       count=" 35."; 
       temps=35;
      }
      if (imgs==125 && resol=="768/768")
      {
       count=" 45."; 
       temps=45;
      }
      if (imgs==125 && resol=="512/512")
      {
       count=" 95."; 
       temps=95;
      }
      if (imgs==250 && resol=="1024/1024")
      {
       count=" 15."; 
       temps=15;
      }
      if (imgs==250 && resol=="1024/768")
      {
       count=" 20."; 
       temps=20;
      }
      if (imgs==250 && resol=="768/768")
      {
       count=" 30."; 
       temps=25;
      }
      if (imgs==250 && resol=="512/512")
      {
       count=" 55."; 
       temps=50;
      }
      if (imgs==500 && resol=="1024/1024")
      {
       count=" 10."; 
       temps=10;
      }
      if (imgs==500 && resol=="1024/768")
      {
       count=" 40."; 
       temps=10;
      }
      if (imgs==500 && resol=="768/768")
      {
       count=" 60."; 
       temps=14;
      }
      if (imgs==500 && resol=="512/512")
      {
       count=" 70."; 
       temps=25;
      }
      if (imgs==1000 && resol=="1024/1024")
      {
       count=" 5."; 
       temps=5;
      }
      if (imgs==1000 && resol=="1024/768")
      {
       count=" 7."; 
       temps=7;
      }
      if (imgs==1000 && resol=="768/768")
      {
       count=" 13."; 
       temps=9;
      }
      if (imgs==1000 && resol=="512/512")
      {
       count=" 75."; 
       temps=16;
      }
      if (imgs==1500 && resol=="768/768")
      {
       count=" 78."; 
       temps=11;
      }
      if (imgs==1500 && resol=="512/512")
      {
       count=" 80."; 
       temps=13;
      }
      if (imgs==2000 && resol=="512/512")
      {
       count=" 83."; 
       temps=13;
      }
      if (imgs==3000 && resol=="512/512")
      {
       count=" 90."; 
       temps=9;
      }
      Serial.print(count);
      while(i<100)
      {
        i++;
        GD.cmd_gradient(0, 0,   0x1919F1,
                    480, 480, 0x2AAAEF);  
        GD.ColorRGB(GREEN);
        dwl += 1;
        GD.cmd_progress(100, 100, 300, 30, 0, dwl, 100);
        GD.ColorRGB(WHITE);
        GD.cmd_text(240, 200, 31, OPT_CENTER, "Mise a jour...");
        delay(25);
        GD.swap();
      }
      delay (500);
      maj=1;
      dwl=0;
      }
}

I needed to add some value for the time and did this :
But now the arduino is not able to start. He compile but the screen of the gameduino 2 stay black.

int miseajour() //function Downlaod
{
    int i=0;
   
      if (imgs==60 && resol=="1024/1024")
      {
        if (time==1)
        {
           count=" 50."; 
           temps=5;
        }
        else if (time==2) 
        {
           count=" 51."; 
           temps=6;
        }
        else if (time==5) 
        {
           count=" 52."; 
           temps=9;
        }
        else if (time==10)
        {
           count=" 53."; 
           temps=14;
        }
      }
      if (imgs==60 && resol=="1024/768")
      {
        if (time==1)
        {
           count=" 65."; 
           temps=5;
        }
        else if (time==2) 
        {
           count=" 66."; 
           temps=6;
        }
        else if (time==5) 
        {
           count=" 67."; 
           temps=9;
        }
        else if (time==10)
        {
           count=" 68."; 
           temps=14;
        }

      }
      if (imgs==60 && resol=="768/768")
      {
        if (time==1)
        {
           count=" 85."; 
           temps=5;
        }
        else if (time==2) 
        {
           count=" 86."; 
           temps=6;
        }
        else if (time==5) 
        {
           count=" 87."; 
           temps=9;
        }
        else if (time==10)
        {
           count=" 88."; 
           temps=14;
        }
      }
      if (imgs==60 && resol=="512/512")
      {
        if (time==1)
        {
           count=" 190."; 
           temps=5;
        }
        else if (time==2) 
        {
           count=" 191."; 
           temps=6;
        }
        else if (time==5) 
        {
           count=" 192."; 
           temps=9;
        }
        else if (time==10)
        {
           count=" 193."; 
           temps=14;
        }
      }
      if (imgs==125 && resol=="1024/1024")
      {
        if (time==1)
        {
           count=" 25."; 
           temps=5;
        }
        else if (time==2) 
        {
           count=" 26."; 
           temps=6;
        }
        else if (time==5) 
        {
           count=" 27."; 
           temps=9;
        }
        else if (time==10)
        {
           count=" 28."; 
           temps=14;
        }
      }
      if (imgs==125 && resol=="1024/768")
      {
        if (time==1)
        {
           count=" 35."; 
           temps=5;
        }
        else if (time==2) 
        {
           count=" 36."; 
           temps=6;
        }
        else if (time==5) 
        {
           count=" 37."; 
           temps=9;
        }
        else if (time==10)
        {
           count=" 38."; 
           temps=14;
        }
      }
      if (imgs==125 && resol=="768/768")
      {
        if (time==1)
        {
           count=" 45."; 
           temps=5;
        }
        else if (time==2) 
        {
           count=" 46."; 
           temps=6;
        }
        else if (time==5) 
        {
           count=" 47."; 
           temps=9;
        }
        else if (time==10)
        {
           count=" 48."; 
           temps=14;
        }
      }
      if (imgs==125 && resol=="512/512")
      {
        if (time==1)
        {
           count=" 95."; 
           temps=5;
        }
        else if (time==2) 
        {
           count=" 96."; 
           temps=6;
        }
        else if (time==5) 
        {
           count=" 97."; 
           temps=9;
        }
        else if (time==10)
        {
           count=" 98."; 
           temps=14;
        }
      }
      if (imgs==250 && resol=="1024/1024")
      {
        if (time==1)
        {
           count=" 15."; 
           temps=5;
        }
        else if (time==2) 
        {
           count=" 16."; 
           temps=6;
        }
        else if (time==5) 
        {
           count=" 17."; 
           temps=9;
        }
        else if (time==10)
        {
           count=" 18."; 
           temps=14;
        }
      }
      
     ..... and the same thing for each case

      Serial.print(count);
      while(i<100)
      {
        i++;
        GD.cmd_gradient(0, 0,   0x1919F1,
                    480, 480, 0x2AAAEF);  
        GD.ColorRGB(GREEN);
        dwl += 1;
        GD.cmd_progress(100, 100, 300, 30, 0, dwl, 100);
        GD.ColorRGB(WHITE);
        GD.cmd_text(240, 200, 31, OPT_CENTER, "Mise a jour...");
        delay(25);
        GD.swap();
      }
      delay (500);
      maj=1;
      dwl=0;
    }
}

Any idea ?

Is there a limite of if in 1 function ?

Thanks you

You need to post your code.

All of it, he means.

http://snippets-r-us.com/

Is there a limite of if in 1 function ?

No.

I don't think 'resol=="1024/1024"' does what you think it does. it compares the pointer resol to the pointer to the constant string you created.

You need strcmp().

The comparison works if resol is a String.

oqibidipo:
The comparison works if resol is a String.

Yes, and possibly massive use of "String" objects in the sketch has eaten up all the available RAM, so the sketch won't work any longer, after adding something to it, because of trying to use more RAM than is available in the Atmega.

You have 233 bytes in string literals alone, there.

It was working ? I rather doubt it.

if (imgs==60 && resol=="1024/1024")

michiyon:
As discussed above, if resol is a String the comparison works, another problem with snippets.

Ok so I need to change my "resol" variable for a int ??

And yes its was working with the first code.

Edit: Ok I added int resolu=0; and change all the string for this int.
Still doesnt work ? Any idea how I could code this ?

Any idea how I could code this ?

See replies #1 and 2

No, int has nothing to do with it. As pointed out we do not know if resol was a String or an array of char. The correct answer depends on that important distinction. SO POST ALL YOUR CODE!

Ok sorry guys there is a limite of code caratere on this forum. So I cant post all the code.

http://pastebin.com/ttG23tbe

Here sorry for this Im new on forum and learning every day :slight_smile:

Just attach the code.

Done Awol thanks :slight_smile:

Please read reply #13.

http://pastebin.com/ttG23tbe

I give up.

attach the code. Come on, I just made a pastebin. This is not the end of the world. Srsly.

Is that better for you attach?

en cours.txt (24.3 KB)

Is there a limite of if in 1 function ?

ANSWER

No, there is no (practical) limit.

I would suggest you use IDE Tools-> Auto Format and it will give you better view of your "if" sequence.
You may be able to see your problem.

And another suggestion - cascaded AKA spaghetti code "if" could be replaced with "switch / case" since majority of "if" conditions tested are single variable.

Multiple "if" are generally used when testing for variety of conditions.