DUE + 4,3 LCDTFT trying to write simple touch menu with submenus sketch

Hi
I am currently working on the simple sketch (it is not my , I am using some of the "Button test" code ).
Basicaly it is the simple menu with submenu. When you press button "1" you go to submenu and here is the problem I can not go back to main menu.
I am a real beginner so I asume there are meny errors in the code , and if anyone wishes to help me sorting this out I would be greatfull.
I am using DUE with 4,3 TFT and CTE shield and It took me 5 weeks to get everything to work (UTFT and UTouch).

#include <UTFT.h>
#include <UTouch.h>

// Declare which fonts we will be using
extern uint8_t BigFont[];
UTFT myGLCD(ITDB43,25,26,27,28); // Remember to change the model parameter to suit your display module!
UTouch myTouch( 6, 5, 32, 3, 2);

int x, y;
char stCurrent[20]="";
int stCurrentLen=0;
char stLast[20]="";

/*************************
** Custom functions **
*************************/

void drawButtons()// MENU
{
// Draw the upper row of buttons
for (x=0; x<5; x++)
{
myGLCD.setColor(0, 0, 255);
myGLCD.fillRoundRect (15+(x90), 50, 105+(x90), 110);
myGLCD.setColor(255, 255, 255);
myGLCD.drawRoundRect (15+(x90), 50, 105+(x90), 110);
myGLCD.printNumI(x+1, 52+(x90), 67);
}
// Draw the center row of buttons
for (x=0; x<5; x++)
{
myGLCD.setColor(0, 0, 255);
myGLCD.fillRoundRect (15+(x
90), 130, 105+(x90), 190);
myGLCD.setColor(255, 255, 255);
myGLCD.drawRoundRect (15+(x
90), 130, 105+(x90), 190);
if (x<4)
myGLCD.printNumI(x+6, 52+(x
90), 147);
}
myGLCD.print("0", 413, 147);
// Draw the lower row of buttons
myGLCD.setColor(0, 0, 255);
myGLCD.fillRoundRect (15, 210, 240, 270);
myGLCD.setColor(255, 255, 255);
myGLCD.drawRoundRect (15, 210, 240, 270);
myGLCD.print("Back", 102, 227);
myGLCD.setColor(0, 0, 255);
myGLCD.fillRoundRect (240, 210, 465, 270);
myGLCD.setColor(255, 255, 255);
myGLCD.drawRoundRect (240, 210, 465, 270);
myGLCD.print("Enter", 323, 227);
myGLCD.setBackColor (0, 0, 0);
}

void updateStr(int val)
{
if (stCurrentLen<20)
{
stCurrent[stCurrentLen]=val;
stCurrent[stCurrentLen+1]='\0';
stCurrentLen++;
myGLCD.setColor(0, 255, 0);
myGLCD.print(stCurrent, LEFT, 10);
}
else
{
myGLCD.setColor(255, 0, 0);
myGLCD.print("BUFFER FULL!", CENTER, 192);
delay(500);
myGLCD.print(" ", CENTER, 192);
delay(500);
myGLCD.print("BUFFER FULL!", CENTER, 192);
delay(500);
myGLCD.print(" ", CENTER, 192);
myGLCD.setColor(0, 255, 0);
}
}

// Draw a red frame while a button is touched
void waitForIt(int x1, int y1, int x2, int y2)
{
myGLCD.setColor(255, 0, 0);
myGLCD.drawRoundRect (x1, y1, x2, y2);
while (myTouch.dataAvailable())
myTouch.read();
myGLCD.setColor(255, 255, 255);
myGLCD.drawRoundRect (x1, y1, x2, y2);
}

void drawButtons2()// SUBMENU
{
// Draw the upper row of buttons
for (x=0; x<5; x++)
{
myGLCD.setColor(64, 64, 128);
myGLCD.fillRoundRect (15+(x90), 50, 105+(x90), 110);
myGLCD.setColor(255, 255, 255);
myGLCD.drawRoundRect (15+(x90), 50, 105+(x90), 110);
myGLCD.printNumI(x+1, 52+(x90), 67);
}
// Draw the center row of buttons
for (x=0; x<5; x++)
{
myGLCD.setColor(64, 64, 128);
myGLCD.fillRoundRect (15+(x
90), 130, 105+(x90), 190);
myGLCD.setColor(255, 255, 255);
myGLCD.drawRoundRect (15+(x
90), 130, 105+(x90), 190);
if (x<4)
myGLCD.printNumI(x+6, 52+(x
90), 147);
}
myGLCD.setColor(64, 64, 128);
myGLCD.fillRoundRect (15, 210, 240, 270);
myGLCD.setColor(255, 255, 255);
myGLCD.drawRoundRect (15, 210, 240, 270);
myGLCD.print("Back", 102, 227);

}
/*************************
** Required functions **
*************************/

void setup()
{
// Initial setup
myGLCD.InitLCD();
myGLCD.clrScr();

myTouch.InitTouch();
myTouch.setPrecision(PREC_MEDIUM);

myGLCD.setFont(BigFont);
myGLCD.setBackColor(0, 0, 255);

}

void loop()
{
drawButtons();

while (true)
{
if (myTouch.dataAvailable())
{
myTouch.read();
x=myTouch.getX();
y=myTouch.getY();

if ((y>=50) && (y<=110)) // Upper row
{
if ((x>=15) && (x<=105)) // Button: 1
{
waitForIt(15, 50, 105, 110);
myGLCD.clrScr();
myGLCD.setFont(BigFont);
myGLCD.setColor(255, 255, 255); //submenu
drawButtons2();
if ((y>=210) && (y<=270)) // Lower row
{
if ((x>=15) && (x<=240)) // Button: Clear
{
waitForIt(15, 210, 240, 270);
myGLCD.clrScr();
myGLCD.setFont(BigFont);
myGLCD.setColor(0, 0, 255); //submenu
return;
}

}
//myGLCD.print("SUCCES", 1, 1);
}
if ((x>=105) && (x<=195)) // Button: 2
{
waitForIt(105, 50, 195, 110);
updateStr('2');
}
if ((x>=195) && (x<=285)) // Button: 3
{
waitForIt(195, 50, 285, 110);
updateStr('3');
}
if ((x>=285) && (x<=375)) // Button: 4
{
waitForIt(285, 50, 375, 110);
updateStr('4');
}
if ((x>=375) && (x<=465)) // Button: 5
{
waitForIt(375, 50, 465, 110);
updateStr('5');
}
}

if ((y>=130) && (y<=190)) // Center row
{
if ((x>=15) && (x<=105)) // Button: 6
{
waitForIt(15, 130, 105, 190);
updateStr('6');
}
if ((x>=105) && (x<=195)) // Button: 7
{
waitForIt(105, 130, 195, 190);
updateStr('7');
}
if ((x>=195) && (x<=285)) // Button: 8
{
waitForIt(195, 130, 285, 190);
updateStr('8');
}
if ((x>=285) && (x<=375)) // Button: 9
{
waitForIt(285, 130, 375, 190);
updateStr('9');
}
if ((x>=375) && (x<=465)) // Button: 0
{
waitForIt(375, 130, 465, 190);
updateStr('0');
}
}

if ((y>=210) && (y<=270)) // Lower row
{
if ((x>=15) && (x<=240)) // Button: Clear
{
waitForIt(15, 210, 240, 270);
stCurrent[0]='\0';
stCurrentLen=0;
myGLCD.setColor(0, 0, 0);
myGLCD.fillRect(0, 0, 480, 39);
}
if ((x>=240) && (x<=480)) // Button: Enter
{
waitForIt(240, 210, 464, 270);
if (stCurrentLen>0)
{
for (x=0; x<stCurrentLen+1; x++)
{
stLast[x]=stCurrent[x];
}
stCurrent[0]='\0';
stCurrentLen=0;
myGLCD.setColor(0, 0, 0);
myGLCD.fillRect(0, 0, 480, 39);
myGLCD.setColor(0, 255, 0);
myGLCD.print(stLast, LEFT, 10);
}
else
{
myGLCD.setColor(255, 0, 0);
myGLCD.print("BUFFER EMPTY", CENTER, 192);
delay(500);
myGLCD.print(" ", CENTER, 192);
delay(500);
myGLCD.print("BUFFER EMPTY", CENTER, 192);
delay(500);
myGLCD.print(" ", CENTER, 192);
myGLCD.setColor(0, 255, 0);
}
}
}
}
}
}

Anyone able to help me???
Please

Anyone able to help me???

Sure. The Due forum is down the page a ways.

By the way, they will expect you to post code properly, too.

void waitForIt(int x1, int y1, int x2, int y2)
{
  myGLCD.setColor(255, 0, 0);
  myGLCD.drawRoundRect (x1, y1, x2, y2);
  while (myTouch.dataAvailable())
    myTouch.read();
  myGLCD.setColor(255, 255, 255);
  myGLCD.drawRoundRect (x1, y1, x2, y2);
}

Pretty stupid name for a function that does not wait for anything.

I have the same problem

Erase your skecth ]:D, don't work!

Try with my personal menu-base sketch
UTFT+Utouch menu



Some videos of my actual project:
Menu & Video player
RGB control
Photoframe & graphic test

Board: Arduino Due
LCD: TFT SmartGPU2 3.5" + 2.8" TFT-ILI9325D (with UTFT lib)