Buttons on touchscreen don't work properly

Hello!

I want to try out how buttons work with a simple code.
In the beginning a button called "start" appears. When this button is pressed the screen clears and the word "okay" and a new button called "back" appear. When the back-button is pressed the screen shall clear again and the loop begins from the top.

#include <UTFT.h>
#include <ITDB02_Touch.h>
#include <UTFT_Buttons_ITDB.h>

extern uint8_t SmallFont[];
extern uint8_t BigFont[];
extern uint8_t Dingbats1_XL[];

UTFT myGLCD(ITDB32WC, 38, 39, 40, 41);
ITDB02_Touch myTouch(6, 5, 4, 3, 2);
UTFT_Buttons myButtons(&myGLCD, &myTouch);

int butStop, pressed_button, butStart, butBack;


void setup() {
  myGLCD.InitLCD();
  myGLCD.clrScr();
  myGLCD.setFont(BigFont);
  myTouch.InitTouch(1);
  myTouch.setPrecision(PREC_HI);
  myButtons.setTextFont(BigFont);
  myButtons.setSymbolFont(Dingbats1_XL);

void loop(){
  boolean back = false;
  boolean start = false;
  butStart = myButtons.addButton( 20, 90, 280, 60, "START");
  myButtons.setButtonColors(VGA_BLACK, VGA_GRAY, VGA_WHITE, VGA_BLUE, VGA_AQUA);
  myButtons.drawButtons();

  while(start == false){
  
   if((myTouch.dataAvailable() == true) && (myButtons.checkButtons() == butStart)){
      start = true;
   }
 }
  

  while(start == true){
    myGLCD.clrScr();
    butBack = myButtons.addButton( 20, 90, 280, 60, "BACK");
    myButtons.setButtonColors(VGA_BLACK, VGA_GRAY, VGA_WHITE, VGA_BLUE, VGA_AQUA);
    myButtons.drawButtons();
    myGLCD.setColor(VGA_WHITE);
    myGLCD.print("Okay.", 5, 0);
    delay(200);
    
    while(back == false){
      myGLCD.setColor(VGA_WHITE);
      myGLCD.print("Okay.", 5, 20);
      
      if((myTouch.dataAvailable() == true) && (myButtons.checkButtons() == butBack)){
          myGLCD.setColor(VGA_WHITE);
          myGLCD.print("Okay.", 5, 40);
          back = true;
          start = false;
        
      }
    }
  }
  delay(1000);
  myGLCD.clrScr();
  
}

I put an "okay" in every operation that i wanted to check. 2 "okay"s are printed, so the second and third while loop are working well. I guess the problem is that the last if command doesn't work.

Any ideas why?

I guess the problem is that the last if command doesn't work.

It most certainly does work. If what it actually does (which you didn't describe) does not match your expectations (which were not clearly defined), then your expectations are wrong.

Using compound if statements makes it difficult to know which part is not doing what you expect. So, don't do that.

If you had this code:

   if(myTouch.dataAvailable())
   {
      Serial.println("The screen was touched.");
      int whichButton = myButtons.checkButtons();
      Serial.print("It was button ");
      Serial.println(whichButton);
      if(whichButton == butBack)
      {
         Serial.print("Heading back...");
      }
   }

and I ask you to describe what happens, you have a LOT more information to provide me.

Now, my suspicion as to what the problem is is that you have only one button at a time shown, but expect butBack and butStart to have different values. I question whether that is a reasonable assumption.