Seeedstudio v1.0 TFT: Touch for next page?

Hello All,

I've been hacking away at this thing for 4 months now and I cannot figure out to implement a touch navigation. I'm basically 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 Seeed Studio TFT screen on and Arduino Uno. Everything is functioning, it's the code that I cant seem to move forward.

#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);
}
  }
}

Your including the touchscreen menu library, but your not using it, why not?

That library has buttons you can use to switch to another screen as well as go back to the previous screen. The only limiting factor here is your text chunks. What board are you using and how big are the text chunks.

Also Tft.init(); is not the proper way to clear the screen. Use the fillRectangle function.
fillRectangle(0,0, 239, 319, BLACK);

HazardsMind:
Your including the touchscreen menu library, but your not using it, why not?

It was left over in the includes from when I was trying to use it to achieve the desired effect. I thought I might be able to use the standard TFT

if (p.z > ts.pressureThreshhold) {
if(p.y < 320)
{
if(p.x >= 0 && p.x < 240)

to move to next page. But have yet to figure it out.

HazardsMind:
What board are you using and how big are the text chunks.

I'm using an Arduino UNO and the Text is pretty robust, see below for a 2 page example.

#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 

#define TS_MINX 140
#define TS_MAXX 900
#define TS_MINY 120
#define TS_MAXY 940

int color = BLUE;  //Paint brush color

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

void setup()
{

  Tft.init();  //init TFT library
  Tft.init();  //init TFT library
  pinMode(0,OUTPUT);

  Tft.drawString("Prototype",2,140,3,GREEN);

  
  Tft.drawString("All text has been digitally",1,240,1,CYAN);
    Tft.drawString("hand set with code. Much",1,250,1,CYAN);
      Tft.drawString("like a letterpress but with",1,260,1,CYAN);
       Tft.drawString("string dynamics",1,270,1,CYAN);
       Tft.drawString("example",1,300,1,RED);
       Tft.drawString("Tft.drawString,1,300,1,YELLOW)",1,310,1,YELLOW);
  delay(1000); 
  

 Tft.fillRectangle(0, 100, 240, 165,BLACK); //draw rectangle
  
  Tft.drawString("Press",1,110,5,WHITE);
  Tft.drawString("to",50,150,8,WHITE);
  Tft.drawString("start",60,220,4,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)

//Page 1
        Tft.init();  //init TFT library
          pinMode(0,OUTPUT);
      Tft.setDisplayDirect(LEFT2RIGHT);
      Tft.drawString("Clearly we are",2,1,2,GREEN);
      Tft.drawString("in the midst of ",2,20,2,GREEN);
      Tft.drawString("a literary",2,40,2,GREEN);
      Tft.drawString("Revolution",0,59,3,RED);
      Tft.drawString("Or are we?",2,82,2,GREEN);
      Tft.drawString("Most writing",2,102,2,GREEN);
      Tft.drawString("proceeds as if",2,120,2,GREEN);
      Tft.drawString("the Internet",2,140,2,GREEN);
      Tft.drawString("never happened.",2,160,2,RED);

      delay(2000); 
      
      
    }
    //Page 2
    
    Tft.init();  //init TFT library

    Tft.drawString("Nearly a",2,2,2,GREEN);
    Tft.drawString("century",2,20,2,GREEN);
    Tft.drawString("ago, the art",2,40,2,GREEN);
    Tft.drawString("world put to",2,60,2,RED);
    Tft.drawString("rest",0,75,3,RED);
    Tft.drawString("conventional",2,100,2,GREEN);
    Tft.drawString("notions of",2,120,2,CYAN);
    Tft.drawString("originality",2,140,2,RED);
    Tft.drawString("and",2,160,2,GREEN);
    Tft.drawString("replication",2,180,2,CYAN);
    Tft.drawString("with the",2,200,2,GREEN);
    Tft.drawString("gestures of",2,220,2,GREEN);
    Tft.drawString("Marcel Duchamp.",2,240,2,YELLOW);
    delay(5000);
    Tft.drawString("Marcel Duchamp.",2,240,2,BLACK);
       Tft.drawString("Marcel Dachump.",2,240,2,YELLOW);
    delay(1000); 



  }
}

Would text like this be able to function within the Menu Lib for what I'm trying to achieve?

It would help, but it wouldn't be exactly what you need.

What you should do is make each page its own function, then when you touch the screen or a button, it goes to the next page.

Could you point me in the direction of an example of a code being used in that manner?

I don't have anything but take a look at the example files in the touchscreenmenu library.

I have tried manipulate the MenuForms but that code is a mess and I think it's made for buttons.

Will you have a look at this and see if im on the right track? So far it just loops back to "Text1" over and over again. But I think cases may be the way to go.

#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) p.y =0;
    else p.y++;
    {
      if(p.x >= 0 && p.x < 240)
      
          pinMode(0,OUTPUT);

switch(p.y)
{
  case 0:

  Tft.init();  //init TFT library
  Tft.drawString("Text1",50,160,4,WHITE);

   break;
   
   case 1:
   
Tft.init();  //init TFT library
  
  Tft.drawString("Text2",50,160,4,WHITE);

break;

case 2:

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);

break;
}
}
}
}

Try this.

#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

#define maxPages 3

unsigned int color = BLUE;  //Paint brush color.. doesnt matter
bool lastT = 1;
byte page = 0;

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!

  boolean T = TouchButton(0, 0, 239, 319);// Detect  touch anywhere
  
  if (T != lastT)
  {
    lastT = T;
    switch (page)
    {
      case 0:

        //Tft.init();  //init TFT library
        Tft.drawString("Text1", 50, 160, 4, WHITE);

        break;

      case 1:
        //Tft.init();  //init TFT library
        Tft.drawString("Text2", 50, 160, 4, WHITE);

        break;

      case 2:
        //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);

        break;
    }
    if(page < maxPages)
      page++;
    else 
      page = 0;
  }
}


boolean TouchButton(int x1, int y1, int x2, int y2)
{
  Point p = TS.getPoint();

  if (x1 > x2)
    swap(int , x1 , x2);

  if (y1 > y2)
    swap(int , y1 , y2);

  if ((p.x >= x1) && (p.x <= x2) && (p.y >= y1) && (p.y <= y2)) return true; // If the buttons coords are touched, return true.
  return false; // button coords were not touched, return false.
}