Hi David
I am including following libraries:
#include <Adafruit_TFTLCD.h>
#include <Adafruit_GFX.h>
#include <TouchScreen.h>
I am not sure what you mean by "which example name gives a problem"
I get no error message. After Uploading, It does show the the programmed screen first and then the display just turns white after half a second. The display stays white until I download the code again.
The bug seems to be random. As soon I change setting in cursor line for position or size, it may work or not.
e.g. change setCursor to 35,48 as showm here insead of 30,48 and the screen goes white.
In code:
void Screenhome (){
// Taste1
tft.setCursor(35,48);
I tried it with an Arduino Uno and Mega. I tried several Arduinos but it shows the same bug.
Thank you very much for your support.
Here is the whole code:
#include <Adafruit_TFTLCD.h> // Library
#include <Adafruit_GFX.h>
#include <TouchScreen.h>
#define LCD_CS A3 // Pin used by LCD
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
#define LCD_RESET A4
#define TS_MINX 125 // value found by screen calibaratiomn (only enter once)
#define TS_MINY 93
#define TS_MAXX 908
#define TS_MAXY 908
#define YP A3 // define the pins to activate LCD
#define XM A2
#define YM 9
#define XP 8
#define BLACK 0x0000 // define color code
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
const int text = 3;
const int texts = 2;
String Statustext = "WERKSTATTSTATUS";
Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET); //fixed defines used by TFT LCD Library
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 364); //fixed defines used by Touch Screen library
boolean buttonEnabled = true;
//------------------------------------------------------------------------------------------------------
void setup() {
Serial.begin(9600);
tft.reset();
uint16_t identifier = tft.readID(); // Start Comunication with Touch
tft.begin(identifier);
tft.setRotation(1); // hoch
tft.fillScreen(BLACK);
}
void loop() {
Screenhome();
Status();
Button();
TestLCD();
}
void Screenhome (){
// Zeichnen der Tasten
// Taste1
tft.fillRect(5,35,100,100, RED);
tft.setCursor(30,48);
tft.setTextColor(BLACK);
tft.setTextSize(text);
tft.print("T1");
//Taste2
tft.fillRect(115,35,100,100,RED);
tft.setCursor(150,48);
tft.setTextColor(BLACK);
tft.setTextSize(text);
tft.print("T2");
//Taste3
tft.fillRect(225,35,100,100,RED);
tft.setCursor(250,48);
tft.setTextColor(BLACK);
tft.setTextSize(text);
tft.print("T3");
//Taste4
tft.fillRect(5,140,100,100,RED);
tft.setCursor(25,150);
tft.setTextColor(BLACK);
tft.setTextSize(text);
tft.print("T4");
//Taste5
tft.fillRect(115,140,100,100,YELLOW);
tft.setCursor(150,150);
tft.setTextColor(BLACK);
tft.setTextSize(text);
tft.print("T5");
//Taste 6
tft.fillRect(225,140,100,100,YELLOW);
tft.setCursor(250,150);
tft.setTextColor(BLACK);
tft.setTextSize(text);
tft.print("T6");
}
void Status() {
tft.fillRect(0,0,320,40, BLACK);
tft.setTextSize(texts);
tft.setTextColor(WHITE);
tft.setCursor (44,18);
// 44,2
tft.print (Statustext);
}
void Button (){
TSPoint p = ts.getPoint(); // if touch the programm will display message
if (p.z > ts.pressureThreshhold) {
//Map funtion to convert the value from Touch into pixel
p.x = map(p.x, TS_MAXX, TS_MINX, 0,330);
p.y = map(p.y, TS_MAXY, TS_MINY, 0,480);
}
// Taste 1
if(p.x>65 && p.x<176 && p.y>17 && p.y<148 && buttonEnabled){
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
Statustext = ("T1");
Status();
}
// Taste 2
if(p.x>67 && p.x<172 && p.y>190 && p.y<316 && buttonEnabled){
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
Statustext = ("T2");
Status();
}
// Taste 3
if(p.x>65 && p.x<356 && p.y>362 && p.y<479 && buttonEnabled){
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
Statustext = ("T3");
Status();
}
// Taste 4
if(p.x>202 && p.x<315 && p.y>17 && p.y<146&& buttonEnabled){
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
Statustext = ("T4");
Status();
}
// Taste 5
if(p.x>202 && p.x<323 && p.y>179 && p.y<303 && buttonEnabled){
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
Statustext = ("T5");
Status();
}
// Taste 6
if(p.x>203 && p.x<311 && p.y>357 && p.y<478 && buttonEnabled){
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
Statustext = ("T6");
Status();
}
}
void TestLCD() {
// a point object holds x y and z coordinates
TSPoint p = ts.getPoint();
// we have some minimum pressure we consider 'valid'
// pressure of 0 means no pressing!
if (p.z > ts.pressureThreshhold) {
p.x = map(p.x, TS_MAXX, TS_MINX, 0,320);
p.y = map(p.y, TS_MAXY, TS_MINY, 0,480);
Serial.print("X = "); Serial.print(p.x);
Serial.print("\t Y = "); Serial.print(p.y);
Serial.print("\t Pressure = "); Serial.println(p.z);
}
// delay(50);
}