#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
#include <Fonts/FreeSansBold9pt7b.h>
#include <InterpolationLib.h>
#include <EEPROM.h>
// The FT6206 uses hardware I2C (SCL/SDA)
Adafruit_FT6206 ctp = Adafruit_FT6206();
#define INTROTEXT1 "Pedis"
#define INTROTEXT2 "Wasserstand"
#define VERSIONTEXT "V0.1 02.06.2025"
#define TFT_CS 15
#define TFT_DC 2
//#define TFT_RST 4
#define MESSPIN 34
/*____Calibrate Touchscreen_____*/
#define MINPRESSURE 1 // minimum required force for touch event
#define TS_MINX 370
#define TS_MINY 470
#define TS_MAXX 3700
#define TS_MAXY 3600
/*______End of Calibration______*/
//Hauptschirm Button
#define DISPHEIGHT 320
#define DISPWIDTH 240
#define MAINBUTTONX 160
#define MAINBUTTONW 70
#define MAINBUTTONY 265
#define MAINBUTTONH 45
//Hauptschirm Messanzeigen
#define LITERANZX 60
#define LITERANZY 100
#define PROZENTANZX 80
#define PROZENTANZY 160
#define MWANZX 25
#define MWTANZY 280
//Hauptschirm Prozent-Bar
#define BARPROZX 10
#define BARPROZY 70
#define BARPROZW 20
#define BARPROZH 200
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC /*, TFT_RST*/);
//iaEE.. nur temporär, bis es EEprom gibt, danach lesen aus EEprom
int16_t iaEEpromEinst[8] = {
200, 30, 15, 2000}; //Volumen, Warnung, Alarm, DelayIntro
int16_t iaEEpromKalibLiter[10] = {
5, 55, 85, 100, 0, 0, 0, 0, 0, 0};
int16_t iaEEpromKalibMessw[10] = {
0, 600, 800, 1000, 0, 0, 0, 0, 7689, 9754};
// Arbeitswerte, aus EEprom kopiert
int16_t iaEinst[8];
#define DISPNORM 0
#define DISPEINST 1
#define DISPKALLITER 3
#define DISPKALMESSWERT 4
#define DISPTAST 5
#define DISPTASTL 6
byte DisplayMode;
// Interpolation xValues: Messwerte yValues: Liter
int16_t numValues;
double xValues[10]; // = { 0, 600, 800, 1000, 400, 600, 700, 800, 900, 1000 };
double yValues[10]; // = { 5, 55, 85, 100, 25, 30, 40, 50, 70, 100 };
int16_t intMesswert;
int16_t intAltMesswert;
float fLiter;
float fProzent;
bool bTrigAnzeigeMesswerte;
byte byEinstEdit; //Nummer der editierten Einstellung (1..7) 0: Kopfzeile (ESC)
//Touch Tastatur-Eingabe
long Number;
bool result = false;
bool cancel = false;
bool Touch_pressed = false;
TS_Point p; //Koordinaten
int16_t X,Y; //Touch Koordinaten
void setup() {
Serial.begin(115200);
// Serial.println("Cap Touch Paint!");
pinMode(MESSPIN, INPUT);
Wire.setPins(21, 22); // redefine first I2C port to be on pins 21/22
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.setRotation(0);
SchirmIntro();
int16_t x1;
int16_t y1;
uint16_t w;
uint16_t h;
tft.getTextBounds("das 1233",20,40,&x1,&y1,&w,&h);
Serial.print(String(x1) + " " + String(y1) + " " + String(w) + " " + String(h));
}
void loop(){
int16_t value = analogRead(MESSPIN);
intAltMesswert = intMesswert;
intMesswert = value;
}
/********************************************************************//**
* @brief detects a touch event and converts touch data
* @param[in] None
* @return boolean (true = touch pressed, false = touch unpressed)
*********************************************************************/
bool Touch_Event() {
// Serial.println("TouchEventStart");
p = ctp.getPoint();
delay(200);
// Serial.println(p.z);
if (p.z > 0) {
// Serial.println("Touch Event");
return true;
}
return false;
}
void printTftZentriert(uint16_t x, uint16_t y, String txt) {
int16_t x1; int16_t y1; uint16_t w; uint16_t h;
tft.getTextBounds(txt,0,y,&x1,&y1,&w,&h);
Serial.print(String(txt) + " w:" + String(w) + " DW: " + String(DISPWIDTH) + " x b: " + String(((DISPWIDTH-w-x)/2)+x) );
Serial.println();
tft.setCursor(((DISPWIDTH-w-x)/2)+x, y);
// tft.setCursor(20, 30);
tft.println(txt);
}
void printTftRechtsBuendig(uint16_t x, uint16_t y, String txt) {
int16_t x1; int16_t y1; uint16_t w; uint16_t h;
tft.getTextBounds(txt,0,y,&x1,&y1,&w,&h);
Serial.print(String(txt) + " w:" + String(w) + " x-w: " + String(x-w) + " x b: " + String(((DISPWIDTH-w-x)/2)+x) );
// Serial.println();
tft.setCursor(x-w, y);
// tft.setCursor(20, 30);
tft.println(txt);
}
void SchirmIntro()
{
tft.fillScreen(ILI9341_YELLOW);
// tft.drawRGBBitmap(20,80, Zihatec_Logo,200,60);
tft.setTextSize(3);
tft.setTextColor(ILI9341_BLUE);
// tft.setFont(&FreeSansBold9pt7b);
// tft.setCursor(10, 50);
// printTftZentriert(0,50, INTROTEXT1);
printTftRechtsBuendig(240,50, INTROTEXT1);
// printTftZentriert(INTROTEXT1);
// tft.println(INTROTEXT1);
// tft.setCursor(10, 100);
// tft.println(INTROTEXT2);
tft.setTextSize(3);
printTftZentriert(0,100, INTROTEXT2);
tft.setTextSize(1);
tft.setTextColor(ILI9341_BLACK);
// tft.setCursor(10, 150);
// tft.println(VERSIONTEXT);
printTftZentriert(00,150, VERSIONTEXT);
}