#include <Wire.h>
#include <Adafruit_FT6206.h> // Für den Touchscreen
#include <Adafruit_GFX.h> // Für die Grafiken
#include <Adafruit_ILI9341.h> // Für das Display
#define TFT_CS 15
#define TFT_RST 4
#define TFT_DC 2
Adafruit_FT6206 touchScreen = Adafruit_FT6206();
Adafruit_ILI9341 display = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
// Status der Rechtecke
bool Mitte_Rot = true;
bool Mitte_Blau = false;
bool Mitte_Gruen = false;
if (touchScreen.touched()) {
TS_Point p = touchScreen.getPoint();
// Korrigiere die Ausrichtung der Touch-Koordinaten
p.x = map(p.x, 0, 240, 240, 0); // Falls dein Display 240x320 ist
// Überprüfe, ob der Touchpunkt innerhalb des Rechtecks liegt
if (p.x >= rectX && p.x <= rectX + rectWidth &&
p.y >= rectY && p.y <= rectY + rectHeight) {
Serial.println("Rechteck angeklickt!");
#include <Wire.h>
#include <Adafruit_FT6206.h> // Für den Touchscreen
#include <Adafruit_GFX.h> // Für die Grafiken
#include <Adafruit_ILI9341.h> // Für das Display
#define TFT_CS 15
#define TFT_RST 4
#define TFT_DC 2
Adafruit_FT6206 touchScreen = Adafruit_FT6206();
Adafruit_ILI9341 display = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
bool Mitte_Rot = true;
bool Mitte_Blau = false;
bool Mitte_Gruen = false;
void setup() {
Serial.begin(115200);
if (!touchScreen.begin(40)) {
Serial.println("Touchscreen konnte nicht initialisiert werden.");
while (1);
}
display.begin();
display.setRotation(1);
display.clearDisplay();
display.fillRect(uint16_t 20, uint16_t 100, uint16_t 80, uint16_t 100, uint16_t ILI9341_BLUE);
display.fillRect(uint16_t 120, uint16_t 100, uint16_t 80, uint16_t 100, uint16_t ILI9341_RED);
display.fillRect(uint16_t 220, uint16_t 100, uint16_t 80, uint16_t 100, uint16_t ILI9341_GREEN);
display.display();
}
void loop(){
while(Mitte_Rot == true){
if(Linkes_Rechteck == touched){
display.clearDisplay();
display.fillRect(uint16_t 20, uint16_t 100, uint16_t 80, uint16_t 100, uint16_t ILI9341_GREEN);
display.fillRect(uint16_t 120, uint16_t 100, uint16_t 80, uint16_t 100, uint16_t ILI9341_BLUE);
display.fillRect(uint16_t 220, uint16_t 100, uint16_t 80, uint16_t 100, uint16_t ILI9341_RED);
display.display();
Mitte_Rot = false;
Mitte_Blau = true;
}
if(Rechtes_Rechteck == touched){
display.clearDisplay();
display.fillRect(uint16_t 20, uint16_t 100, uint16_t 80, uint16_t 100, uint16_t ILI9341_RED);
display.fillRect(uint16_t 120, uint16_t 100, uint16_t 80, uint16_t 100, uint16_t ILI9341_GREEN);
display.fillRect(uint16_t 220, uint16_t 100, uint16_t 80, uint16_t 100, uint16_t ILI9341_Blue);
display.display();
Mitte_Rot = false;
Mitte_Gruen = true;
}
}
while(Mitte_Blau == true){
if(Linkes_Rechteck == touched){
display.clearDisplay();
display.fillRect(uint16_t 20, uint16_t 100, uint16_t 80, uint16_t 100, uint16_t ILI9341_RED);
display.fillRect(uint16_t 120, uint16_t 100, uint16_t 80, uint16_t 100, uint16_t ILI9341_GREEN);
display.fillRect(uint16_t 220, uint16_t 100, uint16_t 80, uint16_t 100, uint16_t ILI9341_Blue);
display.display();
Mitte_Blau = false;
Mitte_Gruen = true;
}
if(Rechtes_Rechteck == touched){
display.clearDisplay();
display.fillRect(uint16_t 20, uint16_t 100, uint16_t 80, uint16_t 100, uint16_t ILI9341_BLUE);
display.fillRect(uint16_t 120, uint16_t 100, uint16_t 80, uint16_t 100, uint16_t ILI9341_RED);
display.fillRect(uint16_t 220, uint16_t 100, uint16_t 80, uint16_t 100, uint16_t ILI9341_GREEN);
display.display();
Mitte_Blau = false;
Mitte_Rot = true;
}
}
while(Mitte_Gruen == true){
if(Linkes_Rechteck == touched){
display.clearDisplay();
display.fillRect(uint16_t 20, uint16_t 100, uint16_t 80, uint16_t 100, uint16_t ILI9341_BLUE);
display.fillRect(uint16_t 120, uint16_t 100, uint16_t 80, uint16_t 100, uint16_t ILI9341_RED);
display.fillRect(uint16_t 220, uint16_t 100, uint16_t 80, uint16_t 100, uint16_t ILI9341_GREEN);
display.display();
Mitte_Gruen = false;
Mitte_Rot = true;
}
if(Rechtes_Rechteck == touched){
display.clearDisplay();
display.fillRect(uint16_t 20, uint16_t 100, uint16_t 80, uint16_t 100, uint16_t ILI9341_GREEN);
display.fillRect(uint16_t 120, uint16_t 100, uint16_t 80, uint16_t 100, uint16_t ILI9341_BLUE);
display.fillRect(uint16_t 220, uint16_t 100, uint16_t 80, uint16_t 100, uint16_t ILI9341_RED);
display.display();
Mitte_Gruen = false;
Mitte_Blau = true;
}
}
}