Mein bisheriges Programm:
#include <Elegoo_GFX.h>
#include <Elegoo_TFTLCD.h>
#include <TouchScreen.h>
#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
#define LCD_RESET A4
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
/******************* UI details */
#define BUTTON1_X 120
#define BUTTON1_Y 90
#define BUTTON1_W 200
#define BUTTON1_H 100
#define BUTTON1_SPACING_X 40
#define BUTTON1_SPACING_Y 30
#define BUTTON1_TEXTSIZE 4
#define BUTTON2_X 120
#define BUTTON2_Y 60
#define BUTTON2_W 200
#define BUTTON2_H 70
#define BUTTON2_SPACING_X 40
#define BUTTON2_SPACING_Y 40
#define BUTTON2_TEXTSIZE 4
#define YP A3
#define XM A2
#define YM 9
#define XP 8
#define TS_MINX 120
#define TS_MAXX 900
#define TS_MINY 70
#define TS_MAXY 920
#define STATUS_X 10
#define STATUS_Y 65
int x=1;
int i=0;
Elegoo_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
TouchScreen tt = TouchScreen(XP, YP, XM, YM, 300);
Elegoo_GFX_Button buttons[2];
char buttonlabels1[2][15] = {"Licht", "Loks" };
uint16_t buttoncolors1[2] = {GREEN,GREEN};
Elegoo_GFX_Button buttons2[3];
char buttonlabels2[3][15] = {"Gleis 1", "Gleis 2", "BACK" };
uint16_t buttoncolors2[3] = {GREEN,GREEN,RED};
void setup(void) {
Serial.begin(9600);
Serial.println(F("TFT LCD test"));
#ifdef USE_Elegoo_SHIELD_PINOUT
Serial.println(F("Using Elegoo 2.8\" TFT Arduino Shield Pinout"));
#else
Serial.println(F("Using Elegoo 2.8\" TFT Breakout Board Pinout"));
#endif
Serial.print("TFT size is "); Serial.print(tft.width()); Serial.print("x"); Serial.println(tft.height());
uint16_t identifier = tft.readID();
if(identifier == 0x9325) {
Serial.println(F("Found ILI9325 LCD driver"));
} else if(identifier == 0x9328) {
Serial.println(F("Found ILI9328 LCD driver"));
} else if(identifier == 0x4535) {
Serial.println(F("Found LGDP4535 LCD driver"));
}else if(identifier == 0x7575) {
Serial.println(F("Found HX8347G LCD driver"));
} else if(identifier == 0x9341) {
Serial.println(F("Found ILI9341 LCD driver"));
} else if(identifier == 0x8357) {
Serial.println(F("Found HX8357D LCD driver"));
} else if(identifier==0x0101)
{
identifier=0x9341;
Serial.println(F("Found 0x9341 LCD driver"));
}else {
Serial.print(F("Unknown LCD driver chip: "));
Serial.println(identifier, HEX);
Serial.println(F("If using the Elegoo 2.8\" TFT Arduino shield, the line:"));
Serial.println(F(" #define USE_Elegoo_SHIELD_PINOUT"));
Serial.println(F("should appear in the library header (Elegoo_TFT.h)."));
Serial.println(F("If using the breakout board, it should NOT be #defined!"));
Serial.println(F("Also if using the breakout, double-check that all wiring"));
Serial.println(F("matches the tutorial."));
identifier=0x9341;
}
//*********************Anfang setup für Seite 1
if (x==1){
tft.reset();
tft.begin(identifier);
tft.setRotation(2);
tft.fillScreen(WHITE);
for (uint8_t row=0; row<2; row++) {
for (uint8_t col=0; col<1; col++) {
buttons[col + row*1].initButton(&tft, BUTTON1_X+col*(BUTTON1_W+BUTTON1_SPACING_X),
BUTTON1_Y+row*(BUTTON1_H+BUTTON1_SPACING_Y),
BUTTON1_W, BUTTON1_H, ILI9341_LIGHTGREY, buttoncolors1[col+row*1], ILI9341_LIGHTGREY,
buttonlabels1[col + row*1], BUTTON1_TEXTSIZE);
buttons[col+row*1].drawButton();
}
}
}
//***************
if(x==2){
tft.reset();
tft.begin(identifier);
tft.setRotation(2);
tft.fillScreen(WHITE);
}
}
//****************Ende setup Seite1
#define MINPRESSURE 10
#define MAXPRESSURE 1000
void funktion1() {
digitalWrite(13, HIGH);
TSPoint p = ts.getPoint();
digitalWrite(13, LOW);
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {
p.x = map(p.x, TS_MINX, TS_MAXX, tft.width(), 0);
p.y = (tft.height()-map(p.y, TS_MINY, TS_MAXY, tft.height(), 0));
}
for (uint8_t b=0; b<2; b++) {
if (buttons[b].contains(p.x, p.y)) {
buttons[b].press(true);
} else {
buttons[b].press(false);
}
}
for (uint8_t b=0; b<2; b++) {
if (buttons[b].justReleased()) {
}
if (buttons[b].justPressed()) {
buttons[b].drawButton(true);
if (b == 1) {
seite3();
}
if (b == 0) {
seite2();x=2;
}
delay(200);
}
}
}
void seite2(){
/*uint16_t identifier = tft.readID();
tft.reset();
tft.begin(identifier);
tft.setRotation(2);
tft.fillScreen(WHITE);
for (uint8_t row=0; row<3; row++) {
for (uint8_t col=0; col<1; col++) {
buttons2[col + row*1].initButton(&tft, BUTTON2_X+col*(BUTTON2_W+BUTTON2_SPACING_X),
BUTTON2_Y+row*(BUTTON2_H+BUTTON1_SPACING_Y),
BUTTON2_W, BUTTON2_H, ILI9341_LIGHTGREY, buttoncolors2[col+row*1], ILI9341_LIGHTGREY,
buttonlabels2[col + row*1], BUTTON2_TEXTSIZE);
buttons2[col+row*1].drawButton();
}
}
}*/ //müsste ins Setup, aber darf nur abgerufen werden, wenn x==2 ist!
digitalWrite(13, HIGH);
TSPoint q = tt.getPoint();
digitalWrite(13, LOW);
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
if (q.z > MINPRESSURE && q.z < MAXPRESSURE) {
q.x = map(q.x, TS_MINX, TS_MAXX, tft.width(), 0);
q.y = (tft.height()-map(q.y, TS_MINY, TS_MAXY, tft.height(), 0));
}
for (uint8_t c=0; c<3; c++) {
if (buttons2[c].contains(q.x, q.y)) {
buttons2[c].press(true);
} else {
buttons2[c].press(false);
}
}
for (uint8_t c=0; c<3; c++) {
if (buttons2[c].justReleased()) {
}
if (buttons2[c].justPressed()) {
buttons2[c].drawButton(true);
if (c == 1) {
seite4;Serial.println("1 1");}
if (c == 0) {
seite4();x=2;Serial.println("1 2");}
if (c==2){
funktion1();x=1;Serial.println("1 3");}
delay(200);
}
}
}
void seite3(){
x=3;
uint16_t identifier = tft.readID();
tft.reset();
tft.begin(identifier);
tft.setRotation(2);
tft.fillScreen(BLUE);
unsigned long start =micros;
tft.setCursor(10,120);
tft.setTextColor(ILI9341_BLACK);tft.setTextSize(3);
tft.println("Funktioniert");
}
void seite4(){
uint16_t identifier = tft.readID();
tft.reset();
tft.begin(identifier);
tft.setRotation(2);
tft.fillScreen(BLUE);
unsigned long start =micros;
tft.setCursor(10,120);
tft.setTextColor(ILI9341_BLACK);tft.setTextSize(3);
tft.println("Funktioniert");
}
void loop(void) {
/*Serial.println(x);*/
if (x==1){funktion1();Serial.print(x);}
}