TFT V1.0 Programing: Touch for next page?

Hello All,

I've been hacking away at this thing for 6 months now and I cannot figure out how to implement a simple touch navigation, instead Im just using a delay. I'm working on a small digital book, I want people to be able to touch the screen to advance to the next screen.

It’s a V1.0 TFT screen on and Arduino Uno. Everything is functioning, it’s the code that I cant seem to move forward. This is a mock-up of my digital book, So Text1 is the first page and Text2 the second… ect.

When I try and attempt a code that allows a simple touch to progress to the next page the code either jumps back to the beginning (so it would just repeat Text1 over and over again) or it just skips through everything. Please help.

#include <TouchScreenMenu.h>
#include <cstddef.h>
#include <stdint.h>
#include <TouchScreen.h> 
#include <TFT.h>

#ifdef SEEEDUINO
  #define YP A2   // must be an analog pin, use "An" notation!
  #define XM A1   // must be an analog pin, use "An" notation!
  #define YM 14   // can be a digital pin, this is A0
  #define XP 17   // can be a digital pin, this is A3 
#endif

#ifdef MEGA
  #define YP A2   // must be an analog pin, use "An" notation!
  #define XM A1   // must be an analog pin, use "An" notation!
  #define YM 54   // can be a digital pin, this is A0
  #define XP 57   // can be a digital pin, this is A3 
#endif 

int color = BLUE;  //Paint brush color.. doesnt matter

TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300); //init TouchScreen port pins


void setup()

{

  Tft.init();  //init TFT library and clears the scren
  pinMode(0,OUTPUT);

          //"text",Position X, Position Y, Font Size, Color

  Tft.drawString("First Screen",30,160,2,WHITE);
  Tft.drawString("Touch Now",30,180,2,WHITE);
   
}

void loop()

{
  
   // a point object holds x y and z coordinates.
  Point p = ts.getPoint();
  //^ERROR??? If it says "Point" change it to "TSPoint" and Vise/Versa
  
  //map the ADC value read to into pixel co-ordinates

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

  // we have some minimum pressure we consider 'valid'
  // pressure of 0 means no pressing!

  if (p.z > ts.pressureThreshhold) {

  // Detect  touch anywhere
    if(p.y < 320)
    {
      if(p.x >= 0 && p.x < 240)
      
          pinMode(0,OUTPUT);

Tft.init();  //init TFT library

  Tft.drawString("Text1",50,160,4,WHITE);
  
  delay(2000);
    /*I need a code that will
   hold this text ont he screen 
   and then go to the next Text 
   chunk with a touch of the screen */
   
Tft.init();  //init TFT library
  
  Tft.drawString("Text2",50,160,4,WHITE);

   delay(2000);  
   /*I need a code that will
   hold this text ont he screen 
   and then go to the next Text 
   chunk with a touch of the screen */

Tft.init();  //init TFT library

  Tft.drawString("Text3",50,160,4,WHITE);
  Tft.drawString("here you can",0,20,2,WHITE);
  Tft.drawString("touch to",0,40,2,WHITE);
  Tft.drawString("restart",0,60,2,WHITE);
}
  }
}

Could you use a do – while statement? I used English language to explain below you will have to write the code yourself. I’m not that great at Arduino yet. I have no clue if this will work it’s just an idea I thought of while reading your post looking for help with a similar problem. If the SEEED tft had an interrupt like the Adafruit TFT this would be much easier.

Put you clear screen here so it doesn’t flash

Do (
Display page 1 “add all the stuff you need to display page 1”

Delay for like 50 instead of 2000
)

While (touch screen Z is below a thresh hold value) and (page counter = 1)

If the code gets to this point that means the screen was touched otherwise it would stay in the do-while loop so add 1 to the page counter. Page counter +1

Put you clear screen here so it doesn’t flash

Do (
Display page 2 “add all the stuff you need to display page 2”

Delay for like 50 instead of 2000
)

While (touch screen Z is below a thresh hold value) and (page counter = 2)

Repeat as needed.

After the last page I would put something like this if page counter is greater than last page number set page counter to 1