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