" back " button ?

Hello …

i want make " previous" or " back " button to back to my menu ! so how can i do it :frowning:

here my code

#include <Adafruit_TFTLCD.h> 
#include <Adafruit_GFX.h>    
#include <TouchScreen.h>

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

#define TS_MINX 204
#define TS_MINY 195
#define TS_MAXX 948
#define TS_MAXY 910

#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

Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);

boolean buttonEnabled = true;

void setup() {
  Serial.begin(9600);
  Serial.print("Starting...");
  
  tft.reset();
  tft.begin(0x9341);
  tft.setRotation(1);
  
  tft.fillScreen(BLACK);

  //Draw white frame
  tft.drawRect(0,0,319,240,BLACK);
  
  //Print "Name" Text
    tft.setCursor(50,10);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.print("smart shopping cart");
  
  // print "contact us" text
  tft.fillRect(60,60, 200, 40, BLUE);
  tft.drawRect(60,60,200,40,WHITE);
  tft.setCursor(100,70);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.print("Contact Us");

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

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

  
 
}

void loop() 
{
  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");
   
   p.x = map(p.x, TS_MAXX, TS_MINX, 0, 320);
   p.y = map(p.y, TS_MAXY, TS_MINY, 0, 240);

   {if(p.x>60 && p.x<260 && p.y>180 && p.y<200 && 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);
    
    //Draw frame
   
    //display "contact us" contents
    tft.setCursor(30,50);
    tft.setTextColor(WHITE);
    tft.setTextSize(2);
    tft.print("\n\n   E-mail :\n\n  For-example@hotmail.com");
    
//create " menu" button
  tft.fillRect(10,10, 90, 30, BLUE);
  tft.drawRect(10,10,90,30,WHITE);
  tft.setCursor(20,15);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.print("Menu >");

  
   }}
       
   {if(p.x>60 && p.x<260 && p.y>100 && p.y<130 && 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);
    
    //Draw frame
   
    // display " about us " contents
    tft.setCursor(50,50);
    tft.setTextColor(WHITE);
    tft.setTextSize(2);
    tft.print("\n this project done by \n\n Maram");

    //create " menu" button
  tft.fillRect(10,10, 90, 30, BLUE);
  tft.drawRect(10,10,90,30,WHITE);
  tft.setCursor(20,15);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.print("Menu >");
   }}
   {if(p.x>60 && p.x<260 && p.y>20 && p.y<40 && 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);
    
    //Draw frame
   
    
    tft.setCursor(30,50);
    tft.setTextColor(WHITE);
    tft.setTextSize(2);
    tft.print("\n\n  the clacultor program ");
   }}
   delay(10);  
  }
}

Note : i have 2.8 tft shield touch screen

@maram11, do not cross-post. Other thread removed.

Oh , sorry ..​
Waiting help !!

Let's see how your question does here in Programming Questions.

i want make " previous" or " back " button

Well, it appears to me that you already know how to make buttons. Just make another one.

It doesn't function as back button , it doesn't get me back to the last page !

It doesn't function as back button

What doesn't?

it doesn't get me back to the last page !

What DOES it do?

Typically you would save menu state on a stack whenever you do a button action, and "back" would pop the stack. This can be expensive, memory-wise.

PaulS:
What doesn't?
What DOES it do?

it does nothing

westfw:
Typically you would save menu state on a stack whenever you do a button action, and "back" would pop the stack. This can be expensive, memory-wise.

i don't understand !
explain it with code , please

maram11:
it does nothing

Two questions, one answer with a pronoun that is not defined. Useless response.

Don't bother replying if you can't post code, refer to things in the code, and describe exactly what happens. "I haven't written any code to make something happen" is a perfectly good thing to include in a reply. "It doesn't work" is NOT.

In my own menu library, which acts on single characters, I just keep track of what the user has typed, and recalculate which menu to show whenever there is a re-display.
So if the user has typed S (for Setup), U (for UART parameters), F (for data Format), It might be sitting there showing

8 - 8N1
E - 7E1
O - 7O1
S - 7S1
X - Back

Somewhere off in RAM, I've saved the string "SUF" Typing 8, E, O, or S would call an action function to actually set up the UART. Typing an 'X' would drop one character off of the saved string (leaving "SU".) Typing anything else issues an error message. And then the menu is 'redisplayed' by parsing the saved string, starting at the top of the menu (which is also saved.) (start at top, execute 'S' internally, execute 'U' internally. If they had typed 'X' previously, that would be the end of the string and it would display the U menu. Otherwise it execute 'F' internally and then display the F menu. (this somewhat execution-heavy method is designed to cut down on the memory required to save state. There are more obvious ways to achieve the same thing.