I am having issues with touch screen overall function and lack of examples for use. My code below is a snippet from a larger program, where my TFT and touch works. two problems - the touch response is VERY VERY slow. in the setup call to "wait a touch" works great - one touch, moves on. in the loop - should be any touch, anywhere inc the var - the result though is you end up tapping, touching hard, holding, etc for the var to change. mega laggy. I'd like to also map some buttons like touch in this zone area, do that - but greatly lack examples there.
so - given my cheap TFT (same 2.4 china one most use, can post pic), are there any better library options, or code examples? any reasons for the delay in touch as I have it now? no I need to go measure my resistance and change that 300 number?
#include <Adafruit_GFX_AS8.h> // Core graphics library
#include <Adafruit_ILI9341_AS8.h> // Hardware-specific library
#include <SPFD5408_TouchScreen.h>
.
#define LCD_CS A3 // Chip Select goes to Analog 3
#define LCD_CD A2 // Command/Data goes to Analog 2
#define LCD_WR A1 // LCD Write goes to Analog 1
#define LCD_RD A0 // LCD Read goes to Analog 0
#define LCD_RESET 10 // Can alternately just connect to Arduino's reset pin
//for touch
#define SENSIBILITY 300
#define MINPRESSURE 10
#define MAXPRESSURE 1000
//These are the pins for the touch shield!
#define YP A2
#define XM A3
#define YM 8
#define XP 9
// Calibrate values
#define TS_MINX 194
#define TS_MINY 106
#define TS_MAXX 915
#define TS_MAXY 870
TouchScreen ts = TouchScreen(XP, YP, XM, YM, SENSIBILITY);
int mode = 0;
void setup() {
pinMode(7, OUTPUT);
digitalWrite(7, LOW);
delay(10);
digitalWrite(7, HIGH);
// Setup the LCD
myGLCD.reset();
delay(10);
myGLCD.begin(0x9341);
myGLCD.setRotation(1);
waitOneTouch(true);
}
void loop() {
readScreen();
otherFunctions();
displayRefreshFunctins();
}//end of loop
//*****************************************************
void readScreen()
{
TSPoint p;
p = ts.getPoint();
if ((p.z > MINPRESSURE ))
{
if (mode < 3)
{
mode++;
}
else
{
mode = 0;
}
}
pinMode(XM, OUTPUT); //Pins configures again for TFT control
pinMode(YP, OUTPUT);
}
//*****************************************************
TSPoint waitOneTouch(boolean showMessage) {
// wait 1 touch to exit function
uint8_t save = 0;
if (showMessage) {
save = myGLCD.getRotation(); // Save it
myGLCD.setRotation(0); // Show in normal
//myGLCD.setCursor (80, 250);
//myGLCD.setTextSize (1);
// myGLCD.setTextColor(BLACK);
//myGLCD.println("Touch to proceed");
}
// Wait a touch
TSPoint p;
do {
p = ts.getPoint();
pinMode(XM, OUTPUT); //Pins configures again for TFT control
pinMode(YP, OUTPUT);
} while ((p.z < MINPRESSURE ) || (p.z > MAXPRESSURE));
if (showMessage) {
myGLCD.setRotation(save);
}
return p;
}