sub menu not returning to HomeScreen

//12 June 2018. Edited for use with DUE and UNO screen 2.8"
//multi wire TFT


#include <MCUFRIEND_kbv.h>
#include <Adafruit_GFX.h>
#include <TouchScreen.h>
MCUFRIEND_kbv tft;

#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
#define LCD_RESET A4

#define TS_MINX 167   //
#define TS_MINY 228   //
#define TS_MAXX 880   //
#define TS_MAXY 860   //

#define YP A2  // must be an analog pin, use "An" notation!
#define XM A3  // must be an analog pin, use "An" notation!
#define YM 8   // can be a digital pin
#define XP 9   // can be a digital pin

#define BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF
#define LIGHTGREY 0xDEDB
#define GREY    0xCE79

#define MINPRESSURE 10
#define MAXPRESSURE 1000

TouchScreen ts = TouchScreen(XP, YP, XM, YM, 365); //.......p0
int X, Y, Z;
boolean buttonEnabled = true;
char currentPage;

void setup() {

  Serial.begin(9600);
  Serial.print("Starting...");
  //....
  tft.reset();
  uint16_t identifier = tft.readID();
  tft.begin(identifier);
  tft.setRotation(2);
  // tft.fillScreen(LIGHTGREY);
  {
    HomeScreen();
    currentPage = '0';
  }
}


void loop()    //...............p1
{
  //HomeScreen
  if (currentPage == '0') {
    TSPoint p = ts.getPoint();  //Get touch point

    if (p.z > ts.pressureThreshhold) {
      Serial.print("X = "); Serial.print(p.x);
      Serial.print("\tY = "); Serial.print(p.y);
      Serial.print("\n");
      digitalWrite(13, HIGH);
      TSPoint p = ts.getPoint();
      digitalWrite(13, LOW);

      p.y = map(p.y, TS_MINY, TS_MAXY, 0, 240);
      p.x = map(p.x, TS_MINX, TS_MAXX, 0, 320);

      X = tft.height() - map(p.x, TS_MINX, TS_MAXX, 0, tft.height());
      Y = map(p.y, TS_MINY, TS_MAXY, 0, tft.width());
      Z = p.z;


      {
        //contact us co-ords
        if (p.x > 50 && p.x < 95 && p.y > 5 && p.y < 180 && buttonEnabled)
        {
          buttonEnabled = false; //Disable button

          //This is important, because the libraries are sharing pins
          pinMode(XM, OUTPUT);
          pinMode(YP, OUTPUT);
          currentPage = '1';
          tft.fillScreen(LIGHTGREY);
          contactus();

        }
      }
      //.....................................p2.............................
      {
        //about us co-ords
        if (p.x > 120 && p.x < 165 && p.y > 5 && p.y < 180 && buttonEnabled)
        {
          buttonEnabled = false; //Disable button

          //This is important, because the libraries are sharing pins
          pinMode(XM, OUTPUT);
          pinMode(YP, OUTPUT);
          currentPage = '2';
          tft.fillScreen(LIGHTGREY);
          aboutus();

        }
        //calculator co-ords
        if (p.x > 195 && p.x < 225 && p.y > 5 && p.y < 180 && buttonEnabled)
        {
          buttonEnabled = false; //Disable button

          pinMode(XM, OUTPUT);
          pinMode(YP, OUTPUT);
          currentPage = '3';
          tft.fillScreen(LIGHTGREY);
          calculator();

        }
      }
      delay(10);   //    .....................p3
    }
  }   //end current page 0 or HomeScreen

  // contactus screen ===========================================
  {
    if (currentPage == '1') {
      Serial.print("correct ...........location but");
      // menu button  co-ords

      TSPoint p = ts.getPoint();  //Get touch point

      if (p.z > ts.pressureThreshhold) {
        Serial.print("X = "); Serial.print(p.x);
        Serial.print("\tY = "); Serial.print(p.y);
        Serial.print("\n");
        digitalWrite(13, HIGH);
        TSPoint p = ts.getPoint();
        digitalWrite(13, LOW);

        p.y = map(p.y, TS_MINY, TS_MAXY, 0, 240);
        p.x = map(p.x, TS_MINX, TS_MAXX, 0, 320);

        X = tft.height() - map(p.x, TS_MINX, TS_MAXX, 0, tft.height());
        Y = map(p.y, TS_MINY, TS_MAXY, 0, tft.width());
        Z = p.z;

        if (p.x > 10 && p.x < 80 && p.y > 180 && p.y < 240 && buttonEnabled) {  //menu button XXL co ords
          buttonEnabled = false; //Disable button
          pinMode(XM, OUTPUT);
          pinMode(YP, OUTPUT);
          Serial.print("button is .......jipee............working");
          //goto home screen
          HomeScreen();
          currentPage = '0';
        }
      }
    }
  }                //end contactus screen .......p4 ==============
  
}     //loop end

void HomeScreen()
{
  tft.fillScreen(LIGHTGREY);
  // print "contact us" text
  tft.fillRect(60, 60, 200, 40, BLUE);
  tft.drawRect(60, 60, 200, 40, RED);
  tft.setCursor(100, 70);
  tft.setTextColor(GREEN);
  tft.setTextSize(2);         //...........
  tft.print("Contact Us");

  //print "about us" text
  tft.fillRect(60, 120, 200, 40, BLUE);
  tft.drawRect(60, 120, 200, 40, CYAN);
  tft.setCursor(110, 130);
  tft.setTextColor(CYAN);
  tft.setTextSize(2);
  tft.print("About Us");

  //Print "calculator" text
  tft.fillRect(60, 180, 200, 40,  BLUE);
  tft.drawRect(60, 180, 200, 40, CYAN);
  tft.setCursor(100, 190);
  tft.setTextColor(CYAN);
  tft.setTextSize(2);
  tft.print("Calculator");  //........p5


}

void contactus()
{
  tft.fillScreen(LIGHTGREY);
  //display "contact us" contents
  tft.setCursor(30, 50);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.print("contactus screen ..............");


  //create " menu" button     ...... ..........p6
  tft.fillRect(10, 10, 90, 30, BLUE);
  tft.drawRect(10, 10, 90, 30, WHITE);
  tft.setCursor(20, 15);
  tft.setTextColor(CYAN);
  tft.setTextSize(2);
  tft.print("Menu >");


}

void aboutus()
{

  tft.fillScreen(LIGHTGREY);
  // display " about us " contents
  tft.setCursor(50, 50);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.print("about us");

  //create " menu" button
  tft.fillRect(10, 10, 90, 30, BLUE);
  tft.drawRect(10, 10, 90, 30, CYAN);
  tft.setCursor(20, 15);
  tft.setTextColor(CYAN);
  tft.setTextSize(2);
  tft.print("Menu >");

}

void calculator()
{
  tft.print("calculator screen");
  tft.fillScreen(LIGHTGREY);
  //display "contact us" contents
  tft.setCursor(30, 50);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.print("calculator screen");


  //create " menu" button     ...........  .....p6
  tft.fillRect(10, 10, 90, 30, BLUE);
  tft.drawRect(10, 10, 90, 30, WHITE);
  tft.setCursor(20, 15);
  tft.setTextColor(CYAN);
  tft.setTextSize(2);
  tft.print("Menu >");
  /*
    //       ................. menu   co-ords ...............
    TSPoint p = ts.getPoint();  //Get touch point

    if (p.z > ts.pressureThreshhold) {
    Serial.print("X = "); Serial.print(p.x);
    Serial.print("\tY = "); Serial.print(p.y);
    Serial.print("\n");
    digitalWrite(13, HIGH);
    TSPoint p = ts.getPoint();
    digitalWrite(13, LOW);

    p.y = map(p.y, TS_MINY, TS_MAXY, 0, 240);
    p.x = map(p.x, TS_MINX, TS_MAXX, 0, 320);

    X = tft.height() - map(p.x, TS_MINX, TS_MAXX, 0, tft.height());
    Y = map(p.y, TS_MINY, TS_MAXY, 0, tft.width());
    Z = p.z;

    if (p.x > 10 && p.x < 30 && p.y > 200 && p.y < 240 && buttonEnabled) // The user has pressed inside the blue rectangle
    {
    buttonEnabled = false; //Disable button

    //This is important, because the libraries are sharing pins
    pinMode(XM, OUTPUT);
    pinMode(YP, OUTPUT);

    //Erase the screen
    tft.fillScreen(BLACK);
    HomeScreen();

    }*/
}

Members

When the 'contact us' button is pressed it goes to a sub menu with a 'menu' button at the top. When the 'menu' button is pressed it should go back to the HomeScreen.
I think I've got the '{ & }' wrong. Not quite sure.

Any help would be appreciated to get this working.

Thanks in advance

Get rid of the superfluous braces, reformat the code using the IDE's autoformat, repost, so we can see the wood for the trees.

The way you answer questions say a lot about your character.

The way you format code says just as much.

This is the auto formatted version

But it has superfluous braces

Like I said it could be the braces. Im not sure. The program is stuck in the

  if (currentPage == '1') {
      Serial.print("correct ...........location but");
      // menu button  co-ords[code] loop and I dont know how to fix it.

Ive tried placing the braces in other areas without any success.

I need some expert help please.
Thanks

try to do this:

             HomeScreen();
             //currentPage = '0';
        }
      }
      currentPage = '0';

NO. It did not fix the problem. The second 'loop' for the sub menu is not working. The program does not respond to the button press although the program is in the sub menu.

In #3 I've been told that the braces is superfluous. Reducing them and the program does not compile.

Members
I've deleted the 'currentPage' sections and lesson the braces.The main screen is now reacting when the 'menu' button is pressed.

Please help me as this is doing my head in.

//12 June 2018. 16 June 2018. Edited for use with DUE and UNO screen 2.8"
//multi wire TFT


#include <MCUFRIEND_kbv.h>
#include <Adafruit_GFX.h>
#include <TouchScreen.h>
MCUFRIEND_kbv tft;

#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
#define LCD_RESET A4

#define TS_MINX 167   //
#define TS_MINY 228   //
#define TS_MAXX 880   //
#define TS_MAXY 860   //

#define YP A2  // must be an analog pin, use "An" notation!
#define XM A3  // must be an analog pin, use "An" notation!
#define YM 8   // can be a digital pin
#define XP 9   // can be a digital pin

#define BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF
#define LIGHTGREY 0xDEDB
#define GREY    0xCE79

#define MINPRESSURE 10
#define MAXPRESSURE 1000

TouchScreen ts = TouchScreen(XP, YP, XM, YM, 365); //.......p0
int X, Y, Z;
boolean buttonEnabled = true;
char currentPage;

void setup() {

  Serial.begin(9600);
  Serial.print("Starting...");
  //....
  tft.reset();
  uint16_t identifier = tft.readID();
  tft.begin(identifier);
  tft.setRotation(2);
  tft.fillScreen(LIGHTGREY);

  HomeScreen();


}


void loop()    //...............p1
{
  //HomeScreen

  TSPoint p = ts.getPoint();  

  if (p.z > ts.pressureThreshhold) {
    Serial.print("X = "); Serial.print(p.x);
    Serial.print("\tY = "); Serial.print(p.y);
    Serial.print("\n");
    digitalWrite(13, HIGH);
    TSPoint p = ts.getPoint();
    digitalWrite(13, LOW);

    p.y = map(p.y, TS_MINY, TS_MAXY, 0, 240);
    p.x = map(p.x, TS_MINX, TS_MAXX, 0, 320);

    X = tft.height() - map(p.x, TS_MINX, TS_MAXX, 0, tft.height());
    Y = map(p.y, TS_MINY, TS_MAXY, 0, tft.width());
    Z = p.z;
    {
      //contact us co-ords
      if (p.x > 50 && p.x < 95 && p.y > 5 && p.y < 180 && buttonEnabled) {
        buttonEnabled = false; 
        pinMode(XM, OUTPUT);
        pinMode(YP, OUTPUT);
        tft.fillScreen(LIGHTGREY);
        contactus();

      }
    }
    //.....................................p2.............................
    {
      //about us co-ords
      if (p.x > 120 && p.x < 165 && p.y > 5 && p.y < 180 && buttonEnabled) {
        buttonEnabled = false; 
        pinMode(XM, OUTPUT);
        pinMode(YP, OUTPUT);
        tft.fillScreen(LIGHTGREY);
        aboutus();
      }
    }
    //calculator co-ords
    {
      if (p.x > 195 && p.x < 225 && p.y > 5 && p.y < 180 && buttonEnabled) {
        buttonEnabled = false; 
        pinMode(XM, OUTPUT);
        pinMode(YP, OUTPUT);
        tft.fillScreen(LIGHTGREY);
        calculator();
       }
      }
  
    delay(10);   //    .....................p3

     //end  HomeScreen ..........................................

  // contactus screen ==========SUB====MENU Start==================
  
    {
     Serial.println("correct ...........location but");
     
      if (p.x > 10 && p.x < 80 && p.y > 180 && p.y < 240 && buttonEnabled) {  //menu button XXL co ords
        buttonEnabled = false; 
        pinMode(XM, OUTPUT);
        pinMode(YP, OUTPUT);
        Serial.print("button is .......jipee............working");
        //goto home screen
        HomeScreen();
      }
     } 
  // aboutus screen ==========SUB====MENU Start==================
  
    {
     Serial.println("correct ...........location but");
     
      if (p.x > 10 && p.x < 80 && p.y > 180 && p.y < 240 && buttonEnabled) {  //menu button XXL co ords
        buttonEnabled = false; 
        pinMode(XM, OUTPUT);
        pinMode(YP, OUTPUT);
        Serial.print("button is .......jipee............working");
        //goto home screen
        HomeScreen();
      }
     } 
// calculator screen ==========SUB====MENU Start==================
  
    {
     Serial.println("correct ...........location but");
     
      if (p.x > 10 && p.x < 80 && p.y > 180 && p.y < 240 && buttonEnabled) {  //menu button XXL co ords
        buttonEnabled = false; 
        pinMode(XM, OUTPUT);
        pinMode(YP, OUTPUT);
        Serial.print("button is .......jipee............working");
        //goto home screen
        HomeScreen();
      }
     } 
                  
  }   //if (pz      .......p4 ==============
}     //loop end

void HomeScreen()
{
  tft.fillScreen(LIGHTGREY);
  // print "contact us" text
  tft.fillRect(60, 60, 200, 40, BLUE);
  tft.drawRect(60, 60, 200, 40, RED);
  tft.setCursor(100, 70);
  tft.setTextColor(GREEN);
  tft.setTextSize(2);         //...........
  tft.print("Contact Us");

  //print "about us" text
  tft.fillRect(60, 120, 200, 40, BLUE);
  tft.drawRect(60, 120, 200, 40, CYAN);
  tft.setCursor(110, 130);
  tft.setTextColor(CYAN);
  tft.setTextSize(2);
  tft.print("About Us");

  //Print "calculator" text
  tft.fillRect(60, 180, 200, 40,  BLUE);
  tft.drawRect(60, 180, 200, 40, CYAN);
  tft.setCursor(100, 190);
  tft.setTextColor(CYAN);
  tft.setTextSize(2);
  tft.print("Calculator");  //........p5

}

void contactus()
{
  tft.fillScreen(LIGHTGREY);
  //display "contact us" contents
  tft.setCursor(30, 50);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.print("contactus screen ..............");


  //create " menu" button     ...... ..........p6
  tft.fillRect(10, 10, 90, 30, BLUE);
  tft.drawRect(10, 10, 90, 30, WHITE);
  tft.setCursor(20, 15);
  tft.setTextColor(CYAN);
  tft.setTextSize(2);
  tft.print("Menu >");
}

void aboutus()
{

  tft.fillScreen(LIGHTGREY);
  // display " about us " contents
  tft.setCursor(50, 50);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.print("about us");

  //create " menu" button
  tft.fillRect(10, 10, 90, 30, BLUE);
  tft.drawRect(10, 10, 90, 30, CYAN);
  tft.setCursor(20, 15);
  tft.setTextColor(CYAN);
  tft.setTextSize(2);
  tft.print("Menu >");

}

void calculator()
{
  tft.print("calculator screen");
  tft.fillScreen(LIGHTGREY);
  //display "contact us" contents
  tft.setCursor(30, 50);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.print("calculator screen");


  //create " menu" button     ...........  .....p7
  tft.fillRect(10, 10, 90, 30, BLUE);
  tft.drawRect(10, 10, 90, 30, WHITE);
  tft.setCursor(20, 15);
  tft.setTextColor(CYAN);
  tft.setTextSize(2);
  tft.print("Menu >");
  /*
    //       ................. menu   co-ords ...............
    TSPoint p = ts.getPoint();  //Get touch point

    if (p.z > ts.pressureThreshhold) {
    Serial.print("X = "); Serial.print(p.x);
    Serial.print("\tY = "); Serial.print(p.y);
    Serial.print("\n");
    digitalWrite(13, HIGH);
    TSPoint p = ts.getPoint();
    digitalWrite(13, LOW);

    p.y = map(p.y, TS_MINY, TS_MAXY, 0, 240);
    p.x = map(p.x, TS_MINX, TS_MAXX, 0, 320);

    X = tft.height() - map(p.x, TS_MINX, TS_MAXX, 0, tft.height());
    Y = map(p.y, TS_MINY, TS_MAXY, 0, tft.width());
    Z = p.z;

    if (p.x > 10 && p.x < 30 && p.y > 200 && p.y < 240 && buttonEnabled) // The user has pressed inside the blue rectangle
    {
    buttonEnabled = false; //Disable button

    //This is important, because the libraries are sharing pins
    pinMode(XM, OUTPUT);
    pinMode(YP, OUTPUT);

    //Erase the screen
    tft.fillScreen(BLACK);
    HomeScreen();

    }*/
}

Thanks in advance

    Z = p.z;
    {
      //contact us co-ords

Superfluous brace.

Thanks, but that caused the program to goto line 151 & print 'correct ...........location but' all the time whent I read the serial monitor.

Removing that brace (and its partner) should have no effect on the flow of the code.

The serial monitor print this continuously:

correct ...........location but
correct ...........location but

Ive tested the sub menu (when the 'about us' button is pushed in the HomeScreen) and it does go to the 'sub menu'' area. Still stuck there as the 'menu' button does not return me to the HomeScreen.

Members

Is there another way/ approach to write a sub menu?

Thanks

I've managed to 'sort off' fixed the problem by disabling the buttonEnable section. The program does go to the sub menu (jipeeee) BUT ALL the touch points/buttons are also available in the sub menu.

Not sure how to fix it though so I placed >> . Now the sub menu can be accessed from ALL the screens. Not ideal but it works (sort off)

//12 June 2018. 16 June 2018. Edited for use with DUE and UNO screen 2.8"
//multi wire TFT


#include <MCUFRIEND_kbv.h>
#include <Adafruit_GFX.h>
#include <TouchScreen.h>
MCUFRIEND_kbv tft;

#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
#define LCD_RESET A4

#define TS_MINX 167   //
#define TS_MINY 228   //
#define TS_MAXX 880   //
#define TS_MAXY 860   //

#define YP A2  // must be an analog pin, use "An" notation!
#define XM A3  // must be an analog pin, use "An" notation!
#define YM 8   // can be a digital pin
#define XP 9   // can be a digital pin

#define BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF
#define LIGHTGREY 0xDEDB
#define GREY    0xCE79

#define MINPRESSURE 10
#define MAXPRESSURE 1000

TouchScreen ts = TouchScreen(XP, YP, XM, YM, 365); //.......p0
int X, Y, Z;
//boolean buttonEnabled = true;
//char currentPage;

void setup() {

  Serial.begin(9600);
  Serial.print("Starting...");
  //....
  tft.reset();
  uint16_t identifier = tft.readID();
  tft.begin(identifier);
  tft.setRotation(2);
  tft.fillScreen(LIGHTGREY);

  HomeScreen();
}


void loop()    //...............p1
{

  //HomeScreen
  TSPoint p = ts.getPoint();

  if (p.z > ts.pressureThreshhold) {
    Serial.print("X = "); Serial.print(p.x);
    Serial.print("\tY = "); Serial.print(p.y);
    Serial.print("\n");
    digitalWrite(13, HIGH);
    TSPoint p = ts.getPoint();
    digitalWrite(13, LOW);

    p.y = map(p.y, TS_MINY, TS_MAXY, 0, 240);
    p.x = map(p.x, TS_MINX, TS_MAXX, 0, 320);

    X = tft.height() - map(p.x, TS_MINX, TS_MAXX, 0, tft.height());
    Y = map(p.y, TS_MINY, TS_MAXY, 0, tft.width());
    Z = p.z;

    //menu button co-ords
    if (p.x > 10 && p.x < 35 && p.y > 155 && p.y < 240) { // && buttonEnabled)  {
      //buttonEnabled = false;

      //This is important, because the libraries are sharing pins
      pinMode(XM, OUTPUT);
      pinMode(YP, OUTPUT);

      //Erase the screen
      tft.fillScreen(BLACK);
      HomeScreen();
    }

    //contact us co-ords
    if (p.x > 50 && p.x < 95 && p.y > 5 && p.y < 180) { // && buttonEnabled) {
      //buttonEnabled = false;
      pinMode(XM, OUTPUT);
      pinMode(YP, OUTPUT);
      tft.fillScreen(LIGHTGREY);
      contactus();

    }


    //.....................................p2.............................

    //about us co-ords
    if (p.x > 120 && p.x < 165 && p.y > 5 && p.y < 180) { // && buttonEnabled) {
      //buttonEnabled = false;
      pinMode(XM, OUTPUT);
      pinMode(YP, OUTPUT);
      tft.fillScreen(LIGHTGREY);
      aboutus();

    }

    //calculator co-ords

    if (p.x > 195 && p.x < 225 && p.y > 5 && p.y < 180) { // && buttonEnabled) {
      // buttonEnabled = false;
      pinMode(XM, OUTPUT);
      pinMode(YP, OUTPUT);
      tft.fillScreen(LIGHTGREY);
      calculator();

    }
  } //if (p.z
  //end  HomeScreen ..........................................

  //sub menu

  //TSPoint p = ts.getPoint();

  if (p.z > ts.pressureThreshhold) {
    digitalWrite(13, HIGH);
    TSPoint p = ts.getPoint();
    digitalWrite(13, LOW);

    //menu button co-ords
    if (p.x > 10 && p.x < 35 && p.y > 155 && p.y < 240) { // && buttonEnabled)  {
      //buttonEnabled = true;
      pinMode(XM, OUTPUT);
      pinMode(YP, OUTPUT);

      //Erase the screen
      tft.fillScreen(BLACK);
      HomeScreen();
    }

  } //if (p.z

}  //end loop

void HomeScreen()
{
  tft.fillScreen(LIGHTGREY);

  // print "contact us" text
  tft.fillRect(60, 60, 200, 40, BLUE);
  tft.drawRect(60, 60, 200, 40, RED);
  tft.setCursor(100, 70);
  tft.setTextColor(GREEN);
  tft.setTextSize(2);         //...........
  tft.print("Contact Us");

  //print "about us" text
  tft.fillRect(60, 120, 200, 40, BLUE);
  tft.drawRect(60, 120, 200, 40, CYAN);
  tft.setCursor(110, 130);
  tft.setTextColor(CYAN);
  tft.setTextSize(2);
  tft.print("About Us");

  //Print "calculator" text
  tft.fillRect(60, 180, 200, 40,  BLUE);
  tft.drawRect(60, 180, 200, 40, CYAN);
  tft.setCursor(100, 190);
  tft.setTextColor(CYAN);
  tft.setTextSize(2);
  tft.print("Calculator");  //........p5

  //create " menu" button
  tft.fillRect(10, 10, 90, 30, BLUE);
  tft.drawRect(10, 10, 90, 30, CYAN);
  tft.setCursor(20, 15);
  tft.setTextColor(CYAN);
  tft.setTextSize(2);
  tft.print("Menu >");

}

void contactus()
{
  tft.fillScreen(LIGHTGREY);
  //display "contact us" contents
  tft.setCursor(200, 50);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.print(">>"); //sub screen icon

  tft.setCursor(200, 130);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.print(">>"); //sub screen icon

  tft.setCursor(200, 190);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.print(">>"); //sub screen icon
tft.setCursor(20, 190);  //remove later
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.print(">contact us>"); //sub screen icon

  //create " menu" button     ...... ..........p6
  tft.fillRect(10, 10, 90, 30, BLUE);
  tft.drawRect(10, 10, 90, 30, WHITE);
  tft.setCursor(20, 15);
  tft.setTextColor(CYAN);
  tft.setTextSize(2);
  tft.print("Menu >");

}

void aboutus()
{

  tft.fillScreen(LIGHTGREY);
  // display " about us " contents
  tft.setCursor(200, 50);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.print(">>"); //sub screen icon

  tft.setCursor(200, 130);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.print(">>"); //sub screen icon

  tft.setCursor(200, 190);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.print(">>"); //sub screen icon
tft.setCursor(20, 190);  //remove later
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.print(">about us>"); //sub screen icon
  //create " menu" button
  tft.fillRect(10, 10, 90, 30, BLUE);
  tft.drawRect(10, 10, 90, 30, CYAN);
  tft.setCursor(20, 15);
  tft.setTextColor(CYAN);
  tft.setTextSize(2);
  tft.print("Menu >");

}

void calculator()
{
  tft.print("calculator screen");
  tft.fillScreen(LIGHTGREY);
  //display "contact us" contents
  tft.setCursor(200, 50);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.print(">>"); //sub screen icon

  tft.setCursor(200, 130);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.print(">>"); //sub screen icon

  tft.setCursor(200, 190);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.print(">>"); //sub screen icon
tft.setCursor(20, 190);  //remove later
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.print(">calculator>"); //sub screen icon

  //create " menu" button     ...........  .....p7
  tft.fillRect(10, 10, 90, 30, BLUE);
  tft.drawRect(10, 10, 90, 30, WHITE);
  tft.setCursor(20, 15);
  tft.setTextColor(CYAN);
  tft.setTextSize(2);
  tft.print("Menu >");
  /*
    //       ................. menu   co-ords ...............
    TSPoint p = ts.getPoint();  //Get touch point

    if (p.z > ts.pressureThreshhold) {
    Serial.print("X = "); Serial.print(p.x);
    Serial.print("\tY = "); Serial.print(p.y);
    Serial.print("\n");
    digitalWrite(13, HIGH);
    TSPoint p = ts.getPoint();
    digitalWrite(13, LOW);

    p.y = map(p.y, TS_MINY, TS_MAXY, 0, 240);
    p.x = map(p.x, TS_MINX, TS_MAXX, 0, 320);

    X = tft.height() - map(p.x, TS_MINX, TS_MAXX, 0, tft.height());
    Y = map(p.y, TS_MINY, TS_MAXY, 0, tft.width());
    Z = p.z;

    if (p.x > 10 && p.x < 30 && p.y > 200 && p.y < 240 && buttonEnabled) // The user has pressed inside the blue rectangle
    {
    buttonEnabled = false; //Disable button

    //This is important, because the libraries are sharing pins
    pinMode(XM, OUTPUT);
    pinMode(YP, OUTPUT);

    //Erase the screen
    tft.fillScreen(BLACK);
    HomeScreen();

    }*/
}

I finally managed to finish this as well. # sub menus + Home button.

/*Sub Menu example for Due
 * 12 June 2018. 22 June 2018. 31 Sept2018
Edited for use with DUE and UNO shield screen 2.8"
multi wire TFT ILI9341 240x320
3 Sub menu buttons are displayed on the Home
screen.

*/

#include <MCUFRIEND_kbv.h>
#include <Adafruit_GFX.h>
#include <TouchScreen.h>
MCUFRIEND_kbv tft;

#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
#define LCD_RESET A4

#define TS_MINX 167   //
#define TS_MINY 228   //
#define TS_MAXX 880   //
#define TS_MAXY 860   //

#define YP A2  // must be an analog pin, use "An" notation!
#define XM A3  // must be an analog pin, use "An" notation!
#define YM 8   // can be a digital pin
#define XP 9   // can be a digital pin

#define BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF
#define LIGHTGREY 0xDEDB
#define GREY    0xCE79

#define MINPRESSURE 10
#define MAXPRESSURE 1000

TouchScreen ts = TouchScreen(XP, YP, XM, YM, 365); //.......p0
int X, Y, Z;
char currentPage;


void setup() {

  Serial.begin(9600);
  Serial.print("Starting...");
  tft.reset();
  uint16_t identifier = tft.readID();
  tft.begin(identifier);
  tft.setRotation(2);
  HomeScreen();
  currentPage='0';   //........  ............p1
}


void loop() { 
      //HomeScreen
  if (currentPage=='0'){  
    TSPoint p = ts.getPoint();

    if (p.z > ts.pressureThreshhold) { 
      Serial.print("X = "); Serial.print(p.x);
      Serial.print("\tY = "); Serial.print(p.y);
      Serial.print("\n");
      digitalWrite(13, HIGH);
      TSPoint p = ts.getPoint();
      digitalWrite(13, LOW);

      p.y = map(p.y, TS_MINY, TS_MAXY, 0, 240);
      p.x = map(p.x, TS_MINX, TS_MAXX, 0, 320);

      X = tft.height() - map(p.x, TS_MINX, TS_MAXX, 0, tft.height());
      Y = map(p.y, TS_MINY, TS_MAXY, 0, tft.width());
      Z = p.z;

         //contact us co-ords
      if (p.x > 50 && p.x < 95 && p.y > 5 && p.y < 180) {
        pinMode(XM, OUTPUT);
        pinMode(YP, OUTPUT);
        currentPage='1';
        tft.fillScreen(BLACK);
        contactus();

      }
      //.....................................p2.............................

      //about us co-ords
      if (p.x > 120 && p.x < 165 && p.y > 5 && p.y < 180) {
        pinMode(XM, OUTPUT);
        pinMode(YP, OUTPUT);
        currentPage='2';
        tft.fillScreen(BLACK);
        aboutus();

      }

      //on/off co-ords

      if (p.x > 195 && p.x < 225 && p.y > 5 && p.y < 180) {
        pinMode(XM, OUTPUT);
        pinMode(YP, OUTPUT);
         currentPage='3';
        tft.fillScreen(BLACK);
        onoff();
   }
  }
}  //END currentPage==0

//contact us
if (currentPage=='1'){
  TSPoint p = ts.getPoint();

    if (p.z > ts.pressureThreshhold) { 
      digitalWrite(13, HIGH);
      TSPoint p = ts.getPoint();
      digitalWrite(13, LOW);

      p.y = map(p.y, TS_MINY, TS_MAXY, 0, 240);
      p.x = map(p.x, TS_MINX, TS_MAXX, 0, 320);

      X = tft.height() - map(p.x, TS_MINX, TS_MAXX, 0, tft.height());
      Y = map(p.y, TS_MINY, TS_MAXY, 0, tft.width());
      Z = p.z;

         //MENU co-ords ........................................p3
      if (p.x > 10 && p.x < 35 && p.y > 155 && p.y < 240) {
        pinMode(XM, OUTPUT);
        pinMode(YP, OUTPUT);
        currentPage='0';
        tft.fillScreen(BLACK);
        HomeScreen();
      }
    }
} //END currentPage==1

//about us
if (currentPage=='2'){
  TSPoint p = ts.getPoint();

    if (p.z > ts.pressureThreshhold) { 
      digitalWrite(13, HIGH);
      TSPoint p = ts.getPoint();
      digitalWrite(13, LOW);

      p.y = map(p.y, TS_MINY, TS_MAXY, 0, 240);
      p.x = map(p.x, TS_MINX, TS_MAXX, 0, 320);

      X = tft.height() - map(p.x, TS_MINX, TS_MAXX, 0, tft.height());
      Y = map(p.y, TS_MINY, TS_MAXY, 0, tft.width());
      Z = p.z;

         //MENU co-ords
      if (p.x > 10 && p.x < 35 && p.y > 155 && p.y < 240) {
        pinMode(XM, OUTPUT);
        pinMode(YP, OUTPUT);
        currentPage='0';
        tft.fillScreen(BLACK);
        HomeScreen();
      }
    }
}//END currentPage==2 ...............p4

//on/off
if (currentPage=='3'){
  TSPoint p = ts.getPoint();

    if (p.z > ts.pressureThreshhold) { 
      digitalWrite(13, HIGH);
      TSPoint p = ts.getPoint();
      digitalWrite(13, LOW);

      p.y = map(p.y, TS_MINY, TS_MAXY, 0, 240);
      p.x = map(p.x, TS_MINX, TS_MAXX, 0, 320);

      X = tft.height() - map(p.x, TS_MINX, TS_MAXX, 0, tft.height());
      Y = map(p.y, TS_MINY, TS_MAXY, 0, tft.width());
      Z = p.z;

         //MENU co-ords
      if (p.x > 10 && p.x < 35 && p.y > 155 && p.y < 240) {
        pinMode(XM, OUTPUT);
        pinMode(YP, OUTPUT);
        currentPage='0';
        tft.fillScreen(BLACK);
        HomeScreen();
      }
    }
  }//END currentPage==3 ...........p5
} //END loop
void HomeScreen()
{
  tft.fillScreen(BLACK);
  tft.drawRoundRect(60, 60, 175, 40, 18, WHITE); //x,y,w,h,rad,color
  tft.fillRoundRect(64, 65, 165, 30, 16, RED);
  tft.setCursor(95, 75);  //L Right,U Down
  tft.setTextColor(YELLOW);
  tft.setTextSize(1);         //...........
  tft.print("Contact us");

  //print "about us" text
  tft.drawRoundRect(60, 120, 175, 40, 18, WHITE); //x,y,w,h,rad,color
  tft.fillRoundRect(64, 125, 165, 30, 16, RED);
  tft.setCursor(85, 130);  //L Right,U Down
  tft.setTextColor(YELLOW);
  tft.setTextSize(2);
  tft.print("About us");

  //Print "on/off" text
  tft.fillRoundRect(60, 180, 175, 40, 18, WHITE);
  tft.drawRoundRect(64, 185, 165, 30, 16, RED);
  tft.setCursor(95, 190);
  tft.setTextColor(BLACK);
  tft.setTextSize(2);
  tft.print("On / Off");  //..............p6

  //create " Home" button
  tft.fillRect(10, 10, 90, 30, BLUE);
  tft.drawRect(10, 10, 90, 30, CYAN);
  tft.setCursor(20, 15);
  tft.setTextColor(CYAN);
  tft.setTextSize(2);
  tft.print("Home >");

}

void contactus()  //sub menu
{
  tft.fillScreen(BLACK);
  //display "contact us" contents
  tft.setCursor(200, 50);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.print(">>"); //sub screen icon

  tft.setCursor(200, 130);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.print(">>"); //sub screen icon

  tft.setCursor(200, 190);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.print(">>"); //sub screen icon
  tft.setCursor(20, 190);  //remove later
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.print(">contact us>"); //sub screen icon

  //create " Home" button     ...... .............p7
  tft.fillRect(10, 10, 90, 30, BLUE);
  tft.drawRect(10, 10, 90, 30, WHITE);
  tft.setCursor(20, 15);
  tft.setTextColor(CYAN);
  tft.setTextSize(2);
  tft.print("Home >");

}

void aboutus()   //sub menu
{

  tft.fillScreen(BLACK);
  // display " about us " contents
  tft.setCursor(200, 50);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.print(">>"); //sub screen icon

  tft.setCursor(200, 130);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.print(">>"); //sub screen icon

  tft.setCursor(200, 190);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.print(">>"); //sub screen icon
  
  tft.setCursor(20, 190);  //remove later
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.print(">about us>"); //sub screen icon
  
  //create " Home" button
  tft.fillRect(10, 10, 90, 30, BLUE);
  tft.drawRect(10, 10, 90, 30, CYAN);
  tft.setCursor(20, 15);
  tft.setTextColor(CYAN);
  tft.setTextSize(2);
  tft.print("Home >");

}

void onoff()  //sub menu .............p8
{
  tft.print("on/off screen");
  tft.fillScreen(BLACK);
  //display "contact us" contents
  tft.setCursor(200, 50);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.print(">>"); //sub screen icon

  tft.setCursor(200, 130);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.print(">>"); //sub screen icon

  tft.setCursor(200, 190);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.print(">>"); //sub screen icon
  tft.setCursor(20, 190);  //remove later
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.print(">on/off>"); //sub screen icon

  //create " Home" button     ...........  .....p9
  tft.fillRect(10, 10, 90, 30, BLUE);
  tft.drawRect(10, 10, 90, 30, WHITE);
  tft.setCursor(20, 15);
  tft.setTextColor(CYAN);
  tft.setTextSize(2);
  tft.print("Home >");
}