MCUFRIEND showBMP Problems in compbination with if

I am currently trying to build an art stream deck with a 3.5" display.

So far I'm able to load several pages manually (controlled by "PAGE = ..."), everything works manually, but as soon as I uncomment the 3 lines of code for the touch function, the screen just stays black (the BMPs are somehow not loaded anymore) and I just can't figure out what the problem is.
I hope someone can help me

Here is my code (the three lowest lines are for touch):

String PAGE = "main";
String old_PAGE = "";


void loop()
{


  

  
  if(PAGE != old_PAGE){
    if (PAGE=="test"){
    showBMP("up.bmp",  0*93+13, 0*100+20);//x,y
    showBMP("b/01.bmp",  1*93+13, 0*100+20);//x,y
    showBMP("b/02.bmp",  2*93+13, 0*100+20);//x,y
    showBMP("b/03.bmp",  3*93+13, 0*100+20);//x,y
    showBMP("b/04.bmp",  4*93+13, 0*100+20);//x,y
    
    showBMP("b/05.bmp",  0*93+13, 1*100+20);//x,y
    showBMP("b/06.bmp",  1*93+13, 1*100+20);//x,y
    showBMP("b/07.bmp",  2*93+13, 1*100+20);//x,y
    showBMP("b/08.bmp",  3*93+13, 1*100+20);//x,y
    //showBMP("80.bmp",  4*93+13, 1*100+20);//x,y
    
    showBMP("b/10.bmp",  0*93+13, 2*100+20);//x,y
    showBMP("b/11.bmp",  1*93+13, 2*100+20);//x,y
    showBMP("b/12.bmp",  2*93+13, 2*100+20);//x,y
    showBMP("b/13.bmp",  3*93+13, 2*100+20);//x,y
    showBMP("b/14.bmp",  4*93+13, 2*100+20);//x,y
    }


  else if (PAGE="main"){


    showBMP("internet.bmp",  0*93+13, 0*100+20);//x,y
    showBMP("rahmen.bmp",  1*93+13, 0*100+20);//x,y
    showBMP("rahmen.bmp",  2*93+13, 0*100+20);//x,y
    showBMP("gimp.bmp",  3*93+13, 0*100+20);//x,y
    showBMP("joplin.bmp",  4*93+13, 0*100+20);//x,y
    
    showBMP("rahmen.bmp",  0*93+13, 1*100+20);//x,y
    showBMP("previous.bmp",  1*93+13, 1*100+20);//x,y
    showBMP("play.bmp",  2*93+13, 1*100+20);//x,y
    showBMP("next.bmp",  3*93+13, 1*100+20);//x,y
    showBMP("spotify.bmp",  4*93+13, 1*100+20);//x,y
    
    showBMP("blenderf.bmp",  0*93+13, 2*100+20);//x,y
    showBMP("rahmen.bmp",  1*93+13, 2*100+20);//x,y
    showBMP("blender.bmp",  2*93+13, 2*100+20);//x,y
    showBMP("Signal.bmp",  3*93+13, 2*100+20);//x,y
    showBMP("Firefox.bmp",  4*93+13, 2*100+20);//x,y
  }
  old_PAGE = PAGE;
  }




//if (touch_button()=="button1"){
//  PAGE="test";
//}

And here my function "touch_button()":

String touch_button(){
  uint16_t xpos, ypos;  //screen coordinates
    tp = ts.getPoint();   //tp.x, tp.y are ADC values

    // if sharing pins, you'll need to fix the directions of the touchscreen pins
    pinMode(XM, OUTPUT);
    pinMode(YP, OUTPUT);

    if (tp.z > MINPRESSURE && tp.z < MAXPRESSURE){
      xpos = map(tp.x, TS_LEFT, TS_RT, 0, tft.width());
      ypos = map(tp.y, TS_TOP, TS_BOT, 0, tft.height());

      if (((xpos >= 320)and(xpos <= 450))and((ypos >= 10)and(ypos <= 50))){
        return String("button1");      
      }
      if (((xpos >= 320)and(xpos <= 450))and((ypos >= 70)and(ypos <= 110))){
        return String("button2");
      }
      if (((xpos >= 320)and(xpos <= 450))and((ypos >= 130)and(ypos <= 170))){
        return String("button3");
      }
      if (((xpos >= 320)and(xpos <= 450))and((ypos >= 190)and(ypos <= 230))){
        return String("button4");
      }
      if (((xpos >= 320)and(xpos <= 450))and((ypos >= 250)and(ypos <= 290))){
        return String("button5");
      }


      if (((xpos >= 210)and(xpos <= 280))and((ypos >= 10)and(ypos <= 50))){
        return String("button6");
      }
      if (((xpos >= 210)and(xpos <= 280))and((ypos >= 70)and(ypos <= 110))){
        return String("button7");
      }
      if (((xpos >= 210)and(xpos <= 280))and((ypos >= 130)and(ypos <= 170))){
        return String("button8");
      }
      if (((xpos >= 210)and(xpos <= 280))and((ypos >= 190)and(ypos <= 230))){
        return String("button9");
      }
      if (((xpos >= 210)and(xpos <= 280))and((ypos >= 250)and(ypos <= 290))){
        return String("button10");
      }


      if (((xpos >= 13)and(xpos <= 93))and((ypos >= 10)and(ypos <= 50))){
        return String("button11");
      }
      if (((xpos >= 13)and(xpos <= 93))and((ypos >= 70)and(ypos <= 110))){
        return String("button12");
      }
      if (((xpos >= 13)and(xpos <= 93))and((ypos >= 130)and(ypos <= 170))){
        return String("button13");
      }
      if (((xpos >= 13)and(xpos <= 93))and((ypos >= 190)and(ypos <= 230))){
        return String("button14");
      }
      if (((xpos >= 13)and(xpos <= 93))and((ypos >= 250)and(ypos <= 290))){
        return String("button15");
      }
  
}
return "";
}

I can't remember whether you have a Uno or something bigger.

Remember that String is always a bit suspect when you have limited SRAM.
And your code is incredibly long winded.

Your use of String for a variable called PAGE makes my head hurt.

  else if (PAGE="main"){

This is an assignment and not a simple boolean test.

I suggest that you think in terms of scalar variables.
And use for loops instead of repeated sequences.

My other advice is to use ctrl-T to format your code.
When you see an expression like (PAGE != old_PAGE) it is easier to read than (PAGE=="test") and you would notice if you saw (PAGE = "main") instead of (PAGE="main")

David.

I have an Arduino UNO.
I just didn't have it before because it was used in another project.

I suggest that you tidy up your code.

A Uno should be able to handle a few Touch buttons and show a few BMP images.

Paste or attach the whole program if you want help.

David.

I have now made the function "touch_button()" with for loops and integers instead of strings, now everything works great!
Thanks for the helpful answers, if I make any more mistakes I'll get back to you.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.