SEEED TFT touch shield V2.0

Hello I’m trying to program my SEEED TFT touch shield V2.0 so far I got it so theirs different options and depending on what option you press a LED turns on, off, or blinks, what I want to do is have it so if you press option 1 for example it would go into a sub menu and have different options in that sub menu. My question is how would I 1. clear the screen 2. reassign the areas that you press and 3. if I wanted to go back how would I bring up the main menu with out it refreshing a bunch? Here’s my code so far:

#include <stdint.h>
#include <SeeedTouchScreen.h>
#include <TFTv2.h>
#include <SPI.h>
TouchScreen ts = TouchScreen(XP, YP, XM, YM);
int led = 53;
void setup()
{
TFT_BL_ON;
Tft.TFTinit();
Tft.fillRectangle(50,100,150,50,RED);
Tft.fillRectangle(50,170,150,50, YELLOW);
Tft.fillRectangle(0,0,500,70,GREEN);
Tft.fillRectangle(50,240,150,50, BLUE);
Tft.drawString(“MAIN MENU”,0,20,3,WHITE);
Tft.drawString(“OPTION 1”, 50,120,3,WHITE);
Tft.drawString(“OPTION 2”,50,180,3, WHITE);
Tft.drawString(“OPTION 3” ,50,250,3,WHITE);
pinMode(led, OUTPUT);
}
void loop()
{
Point p = ts.getPoint();
p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240);
p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320);
if (p.z > __PRESURE) {
if(p.x > 50){
if(p.x < 200){
if(p.y > 80){
if( p.y < 130){
digitalWrite(led, HIGH);
}}}}
} if (p.z > __PRESURE) {
if(p.x > 50){
if(p.x < 200){
if(p.y > 150){
if( p.y < 220){
digitalWrite(led, LOW);
}}}}}
if (p.z > __PRESURE) {
if(p.x > 50){
if(p.x < 200){
if(p.y > 250){
if( p.y < 300){
digitalWrite(led, HIGH);
delay(100);
digitalWrite(led, LOW);
delay(100);
}}}}}}

My question is how would I 1. clear the screen

Who the hell knows based on that crap you posted. There is no excuse for this:

        }}}}}}

ONE } per line.
And, how difficult is it to properly indent your code? Or to use Tools + Auto Format?
And, how difficult is it to post your code properly?

I’m sorry is this better? (In my defense I did not know about the auto format function till just now) :
#include <stdint.h>
#include <SeeedTouchScreen.h>
#include <TFTv2.h>
#include <SPI.h>
TouchScreen ts = TouchScreen(XP, YP, XM, YM);
int led = 53;

void setup()
{
TFT_BL_ON;
Tft.TFTinit();
//init TFT library
Tft.setDisplayDirect(LEFT2RIGHT);
Tft.drawString(“UP”,20,20,4,WHITE);
Tft.setDisplayDirect(RIGHT2LEFT);
Tft.drawString(“DOWN”,220,220,4,WHITE);
Tft.setDisplayDirect(DOWN2UP);
Tft.drawString(“LEFT”,20,220,4,WHITE);
Tft.setDisplayDirect(UP2DOWN);
Tft.drawString(“RIGHT”,220,20,4,WHITE);
Tft.fillRectangle(50,100,150,50,RED);
Tft.fillRectangle(50,170,150,50, YELLOW);
Tft.fillRectangle(0,0,500,70,GREEN);
Tft.fillRectangle(50,240,150,50, BLUE);
Tft.drawString(“MAIN MENU”,0,20,3,WHITE);
Tft.drawString(“OPTION 1”, 50,120,3,WHITE);
Tft.drawString(“OPTION 2”,50,180,3, WHITE);
Tft.drawString(“OPTION 3” ,50,250,3,WHITE);
pinMode(led, OUTPUT);
}

void loop()
{
Point p = ts.getPoint();

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

if (p.z > __PRESURE) {

if(p.x > 50){
if(p.x < 200){
if(p.y > 80){
if( p.y < 130){
digitalWrite(led, HIGH);
}
}
}
}
}
if (p.z > __PRESURE) {
if(p.x > 50){
if(p.x < 200){
if(p.y > 150){
if( p.y < 220){

digitalWrite(led, LOW);
}
}
}
}
}
if (p.z > __PRESURE) {
if(p.x > 50){
if(p.x < 200){
if(p.y > 250){
if( p.y < 300){
digitalWrite(led, HIGH);
delay(100);
digitalWrite(led, LOW);
delay(100);
}
}
}
}
}
}

I dont know if this helps but im starting to play with a similar tft from sainsmart/ebay with a mega board

if you can compile and load the examples for buttons from the library example from here Electronics - Henning Karlsen

(worked out of the box for me) you can use the
UTFT.clrScr(); command to clear the screen

If your using an uno the lib is probably too big, and you may need to write your own function to overwrite the screen with the background colour and paint the menu screens you want using the more fundemntal commands available if the feature rich libraries are to too large

void fillscreen(code for fill colour)
for (x=0; x<= max x coordinate); x++)
{
for (y = 0; y<= max y coordinate); y++)
{
write passed colour space @ x,y ( i dont know the functions)
}
}

and functions to pain the pages you want such as

int paintmenu1()

int paintmenu2()

that code's not compatible with my touch screen thanks tho. I need to figure out how to redefine the areas that you touch if you know what I mean.

if (p.z > __PRESURE) {

    if(p.x > 50){
      if(p.x < 200){
        if(p.y > 80){
          if( p.y < 130){ 
            digitalWrite(led, HIGH);
          }
        }
      }
    }
  }

You are allowed to use spaces.

You are allowed to use compound if statements.

 if (p.z > __PRESURE)
 {
    if(p.x > 50 && p.x < 200)
    {
        if(p.y > 80 && p.y < 130)
        { 
            digitalWrite(led, HIGH);
        }
    }
 }

I happened upon this post looking for some TFT guidance and I see how this a-hole PaulS treats “newbies” … like he is some programming god. I went back and looked at some of PaulS’s other posts and do beleive I think I leave more in the toilet every morning than he knows about most subjects he “contributes” to. I suggest a bit more fiber I your diet my grumpy friend.