// ESPHome: https://esphome.io/components/display/ili9xxx.html
// Beispiel-Befehle: https://hartmut-waller.info/arduinoblog/beispielprogramm-tft/
// https://www.youtube.com/watch?v=yTwM_eKBrJM
/*
tft.begin() TFT starten
tft_init(INITR_BLACKTAB); this is used to initialize TFT display - als Alternative zu tft.begin()???
initR(initR(INITR_BLACKTAB);); BLACKTAB GREENTAB REDTAB Farbschema bestimmen
tft.setCursor(x, y); Cursor setzen
tft.height() tft.println(String(tft.height()));
tft.width() 240x320
tft.setTextSize(Textgröße); Textgröße: Textgröße setzen
tft.setTextColor(Farbe); Textfarbe bestimmen
tft.print("Text"); tft.println("Text"); Text schreiben
tft.setTextWrap(true/false); false → Text fließt über den Rand des TFTs hinaus true → Text wird am Ende umgebrochen Zeilenumbruch
tft.setRotation(Richtung); Richtung = 0 → nicht drehen Richtung = 1 → 90° drehen Richtung
= 2 → 180° drehen Richtung = 3 → 270 ° drehen Bildschirm ausrichten
tft.fillScreen(Farbe); Standardfarben:
ILI9341_BLACK ILI9341_WHITE ILI9341_GREEN ILI9341_DARKGREEN ILI9341_RED
ILI9341_BLUE ILI9341_NAVY ILI9341_CASET ILI9341_YELLOW ILI9341_ORANGE
ILI9341_MAGENTA ILI9341_CYAN ILI9341_DARKCYAN ILI9341_LIGHTGREY ILI9341_DARKGREY
ILI9341_GREENYELLOW ILI9341_MAROON Bildschirmhintergrund
tft.drawLine(StartX, StartY, EndeX, EndeY, Farbe); Linie zeichnen
tft.drawFastHLine(StartX, StartY, Länge, Farbe); horizontale Linie zeichnen
tft.drawFastVLine(StartX, StartY, Länge, Farbe); vertikale Linie zeichnen
tft.drawRect(StartX, StartY,, Breite, Höhe, Farbe); Rechteck zeichnen
tft.drawRoundRect(StartX, StartY, Breite, Höhe, Eckenradius, Farbe); abgerundetes Rechteck zeichnen
tft.fillRect(StartX, StartY, Breite, Höhe, Füllfarbe); ausgefülltes Rechteck zeichnen
tft.drawCircle(MittelpunkX, MittelpunktY, Radius, Farbe); Kreis zeichnen
tft.fillCircle(MittelpunktX, MittelpunktY, Radius, Füllfarbe); Ausgefüllten Kreis zeichnen
bitmap: https://javl.github.io/image2cpp/
Komplettes Beispiel
https://smarthomeyourself.de/wiki/esphome/ili9341-tft-lcd/ jedoch ESPHome
https://www.az-delivery.de/blogs/azdelivery-blog-fur-arduino-und-raspberry-pi/1-8-toll-tft-am-esp-32-dev-kit-c-betreiben
ESPRESSIF - nearly all models
https://www.espressif.com/en/products/devkits/esp32-devkitc/overview
*/
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
/* für PS-RAM-Einstellungen
platformio.ini: // ? muss hinzugefügt werden in Platformio.ini
build_flags = -DBOARD_HAS_PSRAM
-DCONFIG_SPIRAM_USE_MALLOC
-mfix-esp32-psram-cache-issue */
#define TFT_DC 2
#define TFT_CS 15
#define rand 7
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
// #define width 240
// #define hight 320
// Definition der Bildschirm-Funktionen
void maske (void);
void temperature (int);
void humidity (int);
void diverses ();
void farbpixel ();
// setup ----------------------------------
void setup() {
tft.begin();
}
// main ------------------------------------
void loop() {
// maske();
// farbpixel ();
// diverses ();
maske();
delay(4000);
}
void farbpixel () {
// Farbpixel random am gesamten Bildschirm
int ROT = 255, GRUEN = 255, BLAU = 255;
tft.fillScreen(ILI9341_BLACK);
for (int i = 0; i < 7000; i ++)
{
int PixelX = random(1, tft.width());
int PixelY = random(1, tft.height());
tft.drawPixel(PixelX, PixelY, tft.color565(random(ROT),random(GRUEN),random(BLAU)));
delay(5);
}
delay(2000);
}
// --------- diverses -----------
void diverses (void) {
int i, j=1;
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(rand, 120);
tft.setTextColor(ILI9341_RED);
tft.setTextSize(3);
tft.println("Hello ESP32");
tft.setCursor(rand, 160);
tft.setTextColor(ILI9341_GREEN);
tft.setTextSize(2);
tft.println("I can do SPI :-)");
delay(2000);
// Textsize ---------------------------
tft.fillScreen(ILI9341_BLACK);
tft.setTextColor(ILI9341_WHITE);
tft.setCursor(0,rand);
for (i=0;i<6;i++) {
// tft.setCursor(0,i);
tft.setTextSize(i);
tft.print("textsize ");
tft.println(i);
delay(2000);
}
// display size -----------------------
tft.setTextSize(1);
tft.fillScreen(ILI9341_YELLOW);
tft.setTextColor(ILI9341_BLUE);
tft.println(String(tft.width()));
tft.println(String(tft.height()));
delay(2000);
}
// Aufbau der Bildschirmmaske -------------
void maske (void)
{
int i, dicke=4;
tft.setRotation(1);
tft.fillScreen(ILI9341_CYAN);
tft.setTextColor(ILI9341_MAGENTA);
for (i=1;i<dicke;i++) {
tft.drawRoundRect(rand+i, rand+i, (tft.width()-2*rand)-2*i, (tft.height()-2*rand)-2*i, rand/2, ILI9341_RED);
tft.drawRoundRect(2*rand+i, 2*rand+i, (tft.width()-4*rand)-2*i, (tft.height()-4*rand)-2*i, rand/2, ILI9341_BLACK);
}
tft.setTextSize(3);
tft.setCursor(30,35);
tft.println("Parameter");
tft.setCursor(30,60);
tft.println("der Hauptmaske:");
for (i=1;i<dicke;i++)
tft.drawLine(20, 100+i, tft.width()-20, 100+i, ILI9341_BLACK);
tft.setTextSize(2);
tft.setCursor(4*rand,120);
tft.println("Temperatur:");
tft.setCursor(4*rand,150);
tft.println("Luftfeuchte:");
tft.setCursor(4*rand,180);
tft.print("Luftdruck:");
}
// void temperature (int);
// void humidity (int);