#include <Adafruit_GFX.h> // Für die Grafiken
#include <SPI.h> // das wird gebraucht fürs Display
#include <Adafruit_ILI9341.h> // Für das Display
#include <Adafruit_FT6206.h> // Für den Touchscreen
#include <Arduino.h> // das wird gebraucht für FT6206
// The FT6206 uses hardware I2C (SCL/SDA)
Adafruit_FT6206 ctp = Adafruit_FT6206();
#define TFT_CS 15
#define TFT_DC 2
//#define TFT_RST 4
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC /*, TFT_RST*/);
// Status der Rechtecke
bool Mitte_Rot = true;
bool Mitte_Blau = false;
bool Mitte_Gruen = false;
void setup() {
Serial.begin(115200);
Serial.println(F("Cap Touch Paint!"));
Wire.setPins(21, 22); // redefine first I2C port to be on pins 10/8
tft.begin();
if (! ctp.begin(40)) { // pass in 'sensitivity' coefficient
Serial.println("Couldn't start FT6206 touchscreen controller");
while (1);
}
Serial.println("Capacitive touchscreen started");
tft.fillScreen(ILI9341_BLACK);
//240x320 screen also x = 240 und y = 320 ich will aber x = 320 und y = 240 darum setRotation um start ovem links
//mache Boxen
tft.setRotation(1);
tft.fillRect(20, 70, 80, 100, ILI9341_BLUE); // x geht von 20 bis 99
tft.fillRect(120, 70, 80, 100, ILI9341_RED); // x geht von 120 bis 199
tft.fillRect(220, 70, 80, 100, ILI9341_GREEN); // x geht von 220 bis 299
//die boxen sind nicht falsch sie liegen richtig das ist bei wokwi so das links der kleine schwarze teil nicht zum bildschirm gehört
}
void loop(){
while(Mitte_Rot == true){
delay(10);
if (! ctp.touched()) {
return;
}
TS_Point p = ctp.getPoint();
// Print out the coordinates
Serial.print("("); Serial.print(p.y);
Serial.print(", "); Serial.print(p.x);
Serial.println(")");
if((p.x >= 70) && (p.x < 170)){
if((p.y >= 20) && (p.y < 100)){
tft.fillScreen(ILI9341_BLACK);
tft.fillRect(20, 70, 80, 100, ILI9341_GREEN);
tft.fillRect(120, 70, 80, 100, ILI9341_BLUE);
tft.fillRect(220, 70, 80, 100, ILI9341_RED);
Mitte_Rot = false;
Mitte_Blau = true;
}
if((p.y >= 220) && (p.y < 300)){
tft.fillScreen(ILI9341_BLACK);
tft.fillRect(20, 70, 80, 100, ILI9341_RED);
tft.fillRect(120, 70, 80, 100, ILI9341_GREEN);
tft.fillRect(220, 70, 80, 100, ILI9341_BLUE);
Mitte_Rot = false;
Mitte_Gruen = true;
}
}
}
while(Mitte_Blau == true){
delay(10);
if (! ctp.touched()) {
return;
}
TS_Point p = ctp.getPoint();
// Print out the coordinates
Serial.print("("); Serial.print(p.y);
Serial.print(", "); Serial.print(p.x);
Serial.println(")");
if((p.x >= 70) && (p.x < 170)){
if((p.y >= 20) && (p.y < 100)){
tft.fillScreen(ILI9341_BLACK);
tft.fillRect(20, 70, 80, 100, ILI9341_RED);
tft.fillRect(120, 70, 80, 100, ILI9341_GREEN);
tft.fillRect(220, 70, 80, 100, ILI9341_BLUE);
Mitte_Blau = false;
Mitte_Gruen = true;
}
if((p.y >= 220) && (p.y < 300)){
tft.fillScreen(ILI9341_BLACK);
tft.fillRect(20, 70, 80, 100, ILI9341_BLUE);
tft.fillRect(120, 70, 80, 100, ILI9341_RED);
tft.fillRect(220, 70, 80, 100, ILI9341_GREEN);
Mitte_Blau = false;
Mitte_Rot = true;
}
}
}
while(Mitte_Gruen == true){
delay(10);
if (! ctp.touched()) {
return;
}
TS_Point p = ctp.getPoint();
// Print out the coordinates
Serial.print("("); Serial.print(p.y);
Serial.print(", "); Serial.print(p.x);
Serial.println(")");
if((p.x >= 70) && (p.x < 170)){
if((p.y >= 20) && (p.y < 100)){
tft.fillScreen(ILI9341_BLACK);
tft.fillRect(20, 70, 80, 100, ILI9341_BLUE);
tft.fillRect(120, 70, 80, 100, ILI9341_RED);
tft.fillRect(220, 70, 80, 100, ILI9341_GREEN);
Mitte_Gruen = false;
Mitte_Rot = true;
}
if((p.y >= 220) && (p.y < 300)){
tft.fillScreen(ILI9341_BLACK);
tft.fillRect(20, 70, 80, 100, ILI9341_GREEN);
tft.fillRect(120, 70, 80, 100, ILI9341_BLUE);
tft.fillRect(220, 70, 80, 100, ILI9341_RED);
Mitte_Gruen = false;
Mitte_Blau = true;
}
}
}
}
Loading
ili9341-cap-touch
ili9341-cap-touch