7" Display mit FT5206 CTP

Hallöchen zusammen,

ich habe mir dieses Display geholt :
7" Touch
Datenblätter Schemas etc. sind dort auch zu finden.

der mitgelieferte Beispielcode funktioniert auch soweit. Nun ist für den TouchController keine Bibliothek eingebunden, sondern alles im Sketch programmiert, was es für mich eigentlich nicht benutzbar macht. Ich habe auch erfolglos diverse FT5xx6 Bibliotheken ausprobiert.
Leider ist der mitgelieferte Beispielsketch sehr schlecht dokumentiert. Vielleicht kann ja einer von Euch licht ins Dunkel bringen. Eigentlich möchte ich nur eine Berührung registrieren und diese dann als x,y Koordinaten weiterverarbeiten. Gestensteuerung ist für dieses Projekt nicht relevant, kann also ignoriert werden.

Beispielsketch:

/***************************************************
//Web: http://www.buydisplay.com
EastRising Technology Co.,LTD
Examples for ER-TFTM070-4V2.1(800x480 Pixels) with Capacitive Touch Panel
I2C Interface for Capacitive Touch Panel,8080 16-bit Interface for Display,5V Power Supply
This program is a demo of how to use capacitive touch panel

Tested and worked with:
Arduino Mega 2560,Arduino Due
Works with Arduino 1.6.0 IDE 
****************************************************/

#include <stdint.h>
#include <UTFT.h>
#include <SPI.h>
#include <Wire.h>


uint8_t addr  = 0x38;  //CTP IIC ADDRESS
// Declare which fonts we will be using
extern uint8_t SmallFont[];

// Set the pins to the correct ones for your development shield
// ------------------------------------------------------------
// Standard Arduino Mega/Due shield            : <display model>,38,39,40,41

#define FT5206_WAKE 11
#define FT5206_INT   48    
// Remember to change the model parameter to suit your display module!
UTFT myGLCD(SSD1963_800480,38,39,40,41);  //(byte model, int RS, int WR, int CS, int RST, int SER)
uint16_t tx, ty;

enum {
  eNORMAL = 0,
  eTEST   = 0x04,
  eSYSTEM = 0x01
};

struct TouchLocation
{
  uint16_t x;
  uint16_t y;
};

TouchLocation touchLocations[5];

uint8_t readFT5206TouchRegister( uint8_t reg );
uint8_t readFT5206TouchLocation( TouchLocation * pLoc, uint8_t num );
uint8_t readFT5206TouchAddr( uint8_t regAddr, uint8_t * pBuf, uint8_t len );

uint32_t dist(const TouchLocation & loc);
uint32_t dist(const TouchLocation & loc1, const TouchLocation & loc2);

bool sameLoc( const TouchLocation & loc, const TouchLocation & loc2 );


uint8_t buf[30];

uint8_t readFT5206TouchRegister( uint8_t reg )
{
  Wire.beginTransmission(addr);
  Wire.write( reg );  // register 0
  uint8_t retVal = Wire.endTransmission();
  
  uint8_t returned = Wire.requestFrom(addr, uint8_t(1) );    // request 6 uint8_ts from slave device #2
  
  if (Wire.available())
  {
    retVal = Wire.read();
  }
  
  return retVal;
}

uint8_t readFT5206TouchAddr( uint8_t regAddr, uint8_t * pBuf, uint8_t len )
{
  Wire.beginTransmission(addr);
  Wire.write( regAddr );  // register 0
  uint8_t retVal = Wire.endTransmission();
  
  uint8_t returned = Wire.requestFrom(addr, len);    // request 1 bytes from slave device #2
  
  uint8_t i;
  for (i = 0; (i < len) && Wire.available(); i++)
  {
    pBuf[i] = Wire.read();
  }
  
  return i;
}

uint8_t readFT5206TouchLocation( TouchLocation * pLoc, uint8_t num )
{
  uint8_t retVal = 0;
  uint8_t i;
  uint8_t k;
  
  do
  {
    if (!pLoc) break; // must have a buffer
    if (!num)  break; // must be able to take at least one
    
    uint8_t status = readFT5206TouchRegister(2);
    
    static uint8_t tbuf[40];
    
    if ((status & 0x0f) == 0) break; // no points detected
    
    uint8_t hitPoints = status & 0x0f;
    
    Serial.print("number of hit points = ");
    Serial.println( hitPoints );
    
    readFT5206TouchAddr( 0x03, tbuf, hitPoints*6);
    
    for (k=0,i = 0; (i < hitPoints*6)&&(k < num); k++, i += 6)
    {
      pLoc[k].x = (tbuf[i+0] & 0x0f) << 8 | tbuf[i+1];
      pLoc[k].y = (tbuf[i+2] & 0x0f) << 8 | tbuf[i+3];
    }
    
    retVal = k;
    
  } while (0);
  
  return retVal;
}

void writeFT5206TouchRegister( uint8_t reg, uint8_t val)
{
  Wire.beginTransmission(addr);
  Wire.write( reg );  // register 0
  Wire.write( val );  // value
  
  uint8_t retVal = Wire.endTransmission();  
}

void readOriginValues(void)
{
  writeFT5206TouchRegister(0, eTEST);
  delay(1);
  //uint8_t originLength = readFT5206TouchAddr(0x08, buf, 8 );
  uint8_t originXH = readFT5206TouchRegister(0x08);
  uint8_t originXL = readFT5206TouchRegister(0x09);
  uint8_t originYH = readFT5206TouchRegister(0x0a);
  uint8_t originYL = readFT5206TouchRegister(0x0b);
  
  uint8_t widthXH  = readFT5206TouchRegister(0x0c);
  uint8_t widthXL  = readFT5206TouchRegister(0x0d);
  uint8_t widthYH  = readFT5206TouchRegister(0x0e);
  uint8_t widthYL  = readFT5206TouchRegister(0x0f);
  
  //if (originLength)
  {
    Serial.print("Origin X,Y = ");
    Serial.print( uint16_t((originXH<<8) | originXL) );
    Serial.print(", ");
    Serial.println( uint16_t((originYH<<8) | originYL) );
    
    Serial.print("Width X,Y = ");
    Serial.print( uint16_t((widthXH<<8) | widthXL) );
    Serial.print(", ");
    Serial.println( uint16_t((widthYH<<8) | widthYL) );
  }
  
}




void setup()
{
  randomSeed(analogRead(0));
  
    Serial.begin(9600);
  Wire.begin();        // join i2c bus (address optional for master)
  
// Setup the LCD
  myGLCD.InitLCD();
 // -------------------------------------------------------------
  pinMode(8, OUTPUT);  //backlight 
  digitalWrite(8, HIGH);//on
// -------------------------------------------------------------
readOriginValues();
  pinMode     (FT5206_WAKE, INPUT);
  digitalWrite(FT5206_WAKE, HIGH );
  writeFT5206TouchRegister(0, eNORMAL); // device mode = Normal
  
  uint8_t periodMonitor = readFT5206TouchRegister(0x89);
  
  Serial.print("periodMonitor = ");
  Serial.println( periodMonitor, HEX );
  
  uint8_t  lenLibVersion = readFT5206TouchAddr(0x0a1, buf, 2 );
  if (lenLibVersion)
  {
    uint16_t libVersion = (buf[0] << 8) | buf[1];
  
    Serial.print("lib version = ");
    Serial.println( libVersion, HEX);
  }
  else
  {
    Serial.println("lib version length is zero");
  }
  
  uint8_t firmwareId = readFT5206TouchRegister( 0xa6 );
  
  Serial.print("firmware ID = ");
  Serial.println( firmwareId);
  
    pinMode     (FT5206_INT, INPUT);
  //digitalWrite(FT5206_INT, HIGH );

 
  myGLCD.setFont(SmallFont);
  
}

uint32_t dist(const TouchLocation & loc)
{
  uint32_t retVal = 0;
  
  uint32_t x = loc.x;
  uint32_t y = loc.y;
  
  retVal = x*x + y*y;
  
  return retVal;
}
uint32_t dist(const TouchLocation & loc1, const TouchLocation & loc2)
{
  uint32_t retVal = 0;
  
  uint32_t x = loc1.x - loc2.x;
  uint32_t y = loc1.y - loc2.y;
  
  retVal = sqrt(x*x + y*y);
  
  return retVal;
}

bool sameLoc( const TouchLocation & loc, const TouchLocation & loc2 )
{
  return dist(loc,loc2) < 50;
}


void loop()
{
  int buf[798];
  int x, x2;
  int y, y2;
  int r;

// Clear the screen and draw the frame
  myGLCD.clrScr();
  
 uint8_t flag = 1;
  static uint16_t w = 800;
  static uint16_t h = 480;
  
  float xScale = 1024.0F/w;
  float yScale = 1024.0F/h;
  
  uint8_t attention = digitalRead(FT5206_INT);
  static uint8_t oldAttention = 1;
  
  uint32_t thisTouchTime = millis();
  uint8_t i=0;   
  
  static 
  uint32_t lastTouchTime = thisTouchTime;
 
 
   
              myGLCD.setColor(0, 0, 0);
            myGLCD.fillRect(0, 0, 799, 479);
         myGLCD.setColor(255, 0, 0);
          myGLCD.print("* www.buydiplay.com  Capacitive touch screen test.Please touch the screen!", CENTER, 1);   
         myGLCD.setColor(0, 255, 255);
          myGLCD.print("*EXIT", LEFT, 460); 
 
while(flag)
 {  
  
    attention = digitalRead(FT5206_INT);
    
     /* Wait around for touch events */
    if (!attention && oldAttention ) 
    {   
      Serial.println("Touch: ");
      
      uint8_t count = readFT5206TouchLocation( touchLocations, 5 );


              
      //static uint8_t lastCount = count;
  
     if (count)
      {
        static TouchLocation lastTouch = touchLocations[0];
        
        if (((thisTouchTime - lastTouchTime) > 10000) && sameLoc( touchLocations[0],lastTouch ) )
        {
            myGLCD.setColor(0, 0, 0);
            myGLCD.fillRect(0, 0, 799, 479);
          lastTouchTime = thisTouchTime; 
   
        }
      
        Serial.print("Time delta = ");
        Serial.print(thisTouchTime - lastTouchTime);
        Serial.print(", dist = ");
        Serial.println( dist(touchLocations[0],lastTouch) );
        
        lastTouch = touchLocations[0];
        
        Serial.println("Locations: ");
        
        for (i = 0; i < count; i++)
        {

         myGLCD.setColor(255, 0, 0);
          myGLCD.print("* www.buydiplay.com  Capacitive touch screen test.Please touch the screen!", CENTER, 1);
          snprintf((char*)buf,sizeof(buf),"(%3d,%3d)",touchLocations[i].x,touchLocations[i].y);
          myGLCD.print((const char *)buf,CENTER,380+16*i);

        if(touchLocations[i].x>=3&&touchLocations[i].x<=40&&touchLocations[i].y>=450&&touchLocations[i].y<=480 )flag=0;

        if(i==0) 
        myGLCD.setColor(0, 0, 255),
        myGLCD.fillCircle(touchLocations[i].x,touchLocations[i].y, 5); 

        else if(i==1)  
         myGLCD.setColor(0, 255, 0),
        myGLCD.fillCircle(touchLocations[i].x,touchLocations[i].y, 5); 

        else if(i==2) 
         myGLCD.setColor(255, 0, 0), 
        myGLCD.fillCircle(touchLocations[i].x,touchLocations[i].y, 5 );   
               
        else if(i==3) 
         myGLCD.setColor(255, 255, 0),     
        myGLCD.fillCircle(touchLocations[i].x,touchLocations[i].y, 5 ); 

         else if(i==4) 
         myGLCD.setColor(255, 0, 255),       
         myGLCD.fillCircle(touchLocations[i].x,touchLocations[i].y, 5 ); 
    
        }
      }
        
    }
  
    else
    {
    }
    
    oldAttention = attention;
  }

  myGLCD.clrScr();
  myGLCD.setColor(255, 0, 0);
  myGLCD.fillRect(0, 0, 799, 13);
  myGLCD.setColor(64, 64, 64);
  myGLCD.fillRect(0, 466, 799, 479);
  myGLCD.setColor(255, 255, 255);
  myGLCD.setBackColor(255, 0, 0);
  myGLCD.print("* EastRising Technology *", CENTER, 1);
  myGLCD.setBackColor(64, 64, 64);
  myGLCD.setColor(255,255,0);
  myGLCD.print(" http://www.buydisplay.com", CENTER, 467);

  myGLCD.setColor(0, 0, 255);
  myGLCD.drawRect(0, 14, 799, 465);

// Draw crosshairs
  myGLCD.setColor(0, 0, 255);
  myGLCD.setBackColor(0, 0, 0);
  myGLCD.drawLine(399, 15, 399, 464);
  myGLCD.drawLine(1, 239, 798, 239);
  for (int i=9; i<790; i+=10)
    myGLCD.drawLine(i, 237, i, 242);
  for (int i=19; i<470; i+=10)
    myGLCD.drawLine(397, i, 402, i);

// Draw sin-, cos- and tan-lines  
  myGLCD.setColor(0,255,255);
  myGLCD.print("Sin", 5, 15);
  for (int i=1; i<798; i++)
  {
    myGLCD.drawPixel(i,239+(sin(((i*1.13)*3.14)/180)*200));
  }
  
  myGLCD.setColor(255,0,0);
  myGLCD.print("Cos", 5, 27);
  for (int i=1; i<798; i++)
  {
    myGLCD.drawPixel(i,239+(cos(((i*1.13)*3.14)/180)*200));
  }

  myGLCD.setColor(255,255,0);
  myGLCD.print("Tan", 5, 39);
  for (int i=1; i<798; i++)
  {
    myGLCD.drawPixel(i,239+(tan(((i*0.9)*3.14)/180)));
  }

  delay(2000);

  myGLCD.setColor(0,0,0);
  myGLCD.fillRect(1,15,798,464);
  myGLCD.setColor(0, 0, 255);
  myGLCD.setBackColor(0, 0, 0);
  myGLCD.drawLine(399, 15, 399, 464);
  myGLCD.drawLine(1, 239, 798, 239);

// Draw a moving sinewave
  x=1;
  for (int i=1; i<(798*20); i++) 
  {
    x++;
    if (x==799)
      x=1;
    if (i>799)
    {
      if ((x==399)||(buf[x-1]==239))
        myGLCD.setColor(0,0,255);
      else
        myGLCD.setColor(0,0,0);
      myGLCD.drawPixel(x,buf[x-1]);
    }
    myGLCD.setColor(0,255,255);
    y=239+(sin(((i*1.65)*3.14)/180)*(200-(i / 100)));
    myGLCD.drawPixel(x,y);
    buf[x-1]=y;
  }

  delay(2000);
  
  myGLCD.setColor(0,0,0);
  myGLCD.fillRect(1,15,798,464);

// Draw some random filled rectangles
  for (int i=0; i<50; i++)
  {
    myGLCD.setColor(random(255), random(255), random(255));
    x=2+random(746);
    y=16+random(397);
    x2=x+50;
    y2=y+50;
    myGLCD.fillRect(x, y, x2, y2);
  }

  delay(2000);
  
  myGLCD.setColor(0,0,0);
  myGLCD.fillRect(1,15,798,464);

// Draw some random filled, rounded rectangles
  for (int i=0; i<50; i++)
  {
    myGLCD.setColor(random(255), random(255), random(255));
    x=2+random(746);
    y=16+random(397);
    x2=x+50;
    y2=y+50;
    myGLCD.fillRoundRect(x, y, x2, y2);
  }
  
  delay(2000);
  
  myGLCD.setColor(0,0,0);
  myGLCD.fillRect(1,15,798,464);

// Draw some random filled circles
  for (int i=0; i<50; i++)
  {
    myGLCD.setColor(random(255), random(255), random(255));
    x=27+random(746);
    y=41+random(397);
    myGLCD.fillCircle(x, y, 25);
  }
  
  delay(2000);
  
  myGLCD.setColor(0,0,0);
  myGLCD.fillRect(1,15,798,464);

// Draw some lines in a pattern
  myGLCD.setColor (255,0,0);
  for (int i=15; i<463; i+=5)
  {
    myGLCD.drawLine(1, i, (i*1.66)-10, 463);
  }
  myGLCD.setColor (255,0,0);
  for (int i=463; i>15; i-=5)
  {
    myGLCD.drawLine(798, i, (i*1.66)+30, 15);
  }
  myGLCD.setColor (0,255,255);
  for (int i=463; i>15; i-=5)
  {
    myGLCD.drawLine(1, i, 770-(i*1.66), 15);
  }
  myGLCD.setColor (0,255,255);
  for (int i=15; i<463; i+=5)
  {
    myGLCD.drawLine(798, i, 810-(i*1.66), 463);
  }
  
  delay(2000);
  
  myGLCD.setColor(0,0,0);
  myGLCD.fillRect(1,15,798,464);

// Draw some random circles
  for (int i=0; i<250; i++)
  {
    myGLCD.setColor(random(255), random(255), random(255));
    x=32+random(736);
    y=45+random(386);
    r=random(30);
    myGLCD.drawCircle(x, y, r);
  }

  delay(2000);
  
  myGLCD.setColor(0,0,0);
  myGLCD.fillRect(1,15,798,464);

// Draw some random rectangles
  for (int i=0; i<250; i++)
  {
    myGLCD.setColor(random(255), random(255), random(255));
    x=2+random(796);
    y=16+random(447);
    x2=2+random(796);
    y2=16+random(447);
    myGLCD.drawRect(x, y, x2, y2);
  }

  delay(2000);
  
  myGLCD.setColor(0,0,0);
  myGLCD.fillRect(1,15,798,464);

// Draw some random rounded rectangles
  for (int i=0; i<250; i++)
  {
    myGLCD.setColor(random(255), random(255), random(255));
    x=2+random(796);
    y=16+random(447);
    x2=2+random(796);
    y2=16+random(447);
    myGLCD.drawRoundRect(x, y, x2, y2);
  }

  delay(2000);
  
  myGLCD.setColor(0,0,0);
  myGLCD.fillRect(1,15,798,464);

  for (int i=0; i<250; i++)
  {
    myGLCD.setColor(random(255), random(255), random(255));
    x=2+random(796);
    y=16+random(447);
    x2=2+random(796);
    y2=16+random(447);
    myGLCD.drawLine(x, y, x2, y2);
  }

  delay(2000);
  
  myGLCD.setColor(0,0,0);
  myGLCD.fillRect(1,15,798,464);

  for (int i=0; i<10000; i++)
  {
    myGLCD.setColor(random(255), random(255), random(255));
    myGLCD.drawPixel(2+random(796), 16+random(447));
  }

  delay(2000);

  myGLCD.fillScr(0, 0, 255);
  myGLCD.setColor(255, 0, 0);
  myGLCD.fillRoundRect(320, 190, 479, 289);
  
  myGLCD.setColor(255, 255, 255);
  myGLCD.setBackColor(255, 0, 0);
  myGLCD.print("www.buydisplay.com", CENTER, 195);
  myGLCD.print("That's it!", CENTER, 213);
  myGLCD.print("Restarting in a", CENTER, 239);
  myGLCD.print("few seconds...", CENTER, 252);
  
  myGLCD.setColor(0, 255, 0);
  myGLCD.setBackColor(0, 0, 255);
  myGLCD.print("Runtime: (msecs)", CENTER, 450);
  myGLCD.printNumI(millis(), CENTER, 465);
  
  delay (10000);
}

Dieser Sketch kann bis zu 5 Berührungen "gleichzeitig" verarbeiten (damit man z.b. 2 Fingerzoom, oder scrollen könnte). Wie schon gesagt, das brauche ich nicht. Ich brauche nur: Aha da wurde auf dem Bildschirm rumgedatscht, also Koordinaten in Variabel schreiben.
Jemand Zeit und Lust mal darüberschauen. Vielleicht @my_xy_projekt ? :thinking: :sweat_smile:

Nach dem Spiel gehts zum Mittag.
Danach....

Viel Spass beim Spiel. Wir gehen nachher noch aufs Boot

Ich schau nur - und die Matildas haben das Halbfinale .... Yess.
Jetzt gehts zum Essen...

Ich habe jetzt etwas rumprobiert und dann einfach mal spasseshalber die Adafruit FT6206 installiert.

Dieser Sketch macht genau was ich will

//This example implements a simple sliding On/Off button. The example
// demonstrates drawing and touch operations.
//
//Thanks to Adafruit forums member Asteroid for the original sketch!
//

#include <SPI.h>
#include <Wire.h>
#include <UTFT.h>
#include <Adafruit_FT6206.h>

// The FT6206 uses hardware I2C (SCL/SDA)
Adafruit_FT6206 ts = Adafruit_FT6206();

#define TFT_CS 20
#define TFT_DC 21
UTFT tft(SSD1963_800, 38, 39, 40, 41); //(byte model, int RS, int WR, int CS, int RST, int SER)

boolean RecordOn = false;

void setup(void)
{
  Serial.begin(9600);
  tft.InitLCD();
    if (!ts.begin(40)) {
     Serial.println("Unable to start touchscreen.");
    }
    else {
     Serial.println("Touchscreen started.");
    }
  pinMode(8, INPUT);
  digitalWrite(8, HIGH);
  tft.fillScr(0, 0, 0);


}

void loop()
{
  // See if there's any  touch data for us
  if (ts.touched())
  {
    // Retrieve a point
    TS_Point p = ts.getPoint();
    int y;
    int x;
    Serial.println(RecordOn);
    Serial.print("X: ");
    Serial.println(p.x);
    Serial.print("Y: ");
    Serial.println(p.y);
  }
}

Ich kriege zwar die Fehlermeldung, dass der Touch nicht gestartet werden konnte, was mir aber egal ist, weil es trotzdem funktioniert.

Allerdings würde mich trotzdem interessieren, weshalb keine FT5206 Library funktioniert. Und was der code im Post #1 macht...Also was er macht ist ja klar, aber wie der funktioniert.

Oh, dann brauch ich ja nicht drauf schaun.
Ansonsten: Deine 5 Touchpoints verstecken sich in dem Array, welches die Structur der Koordinaten aufnimmt.
Machst Du da eine 1 draus, wars das schon fürs Grobe.

ja soweit war ich ja auch schon, aber trotzdem ist der Sketch extrem umfangreich. Aber es läuft ja.....einfach schade dass standardmässig keine Bibliothek läuft....oder ich bin einfach zu doof

Wozu willst du eine Bibliothek? Ich versteht dein Ansinnen noch nicht ganz.

Der sketch zeigt dir, was geht. Was du nicht brauchst, lösche raus.
Dann bau dir eine class und wenn du unbedingt willst, kannst die in eine externe Datei packen.

Genau da liegt ja der Hase im Pfeffer. Ich verstehe den Code eben nicht, und weiss deshalb nicht, was wird benötigt und was nicht. Wenn das so einfach wäre hätte ich das ja so gemacht :crazy_face:
aber ich denke ich werde wirklich die 6206 von adafruit verwenden, weil die ja funktioniert :love_you_gesture:

Ok, ich zerpflück das mal und werd mal sehen, ob ich Deinen touch extrahieren kann.
Wirst aber zum testen mitmachen müssen.

ja klar mach ich mit.
Was mich momentan mehr ärgert, ist die Tatsache, dass ich das jetzt alles auf die UTFT umschreiben muss. Bin schon seit 6 stunden dran :crazy_face:

Ich will nicht stressen, weils momentan funktioniert, aber bist du schon weiter gekommen? Falls nicht gar kein Thema. Ich kann momentan weiterarbeiten. Allerdings habe ich zwischendurch das Problem, dass nach einem Neustart noch ein Touchwert gespeichert ist, und dann direkt aus dem Menu in eine Unterseite gesprungen wird. Ist aber Momentan nur Nervig und nicht Projektrelevant

Ich hab das noch als offenes Fenster - aber z. Glück auch seit 3 Tagen ein anderes Leben.
Wenn ich das Projekt Sonnentracker zerlegt habe, bist Du dran.
Aber mehr als 20 Zeilen Code sind im Moment eine Herausforderung für mich...

hey, geniess dein Leben....alles ausserhalb ist nur Ablenkung. Privat ist immer wichtiger als Community

1 Like

Kannst Du mir mal erzählen, wo Du die UTFT her hast?
rinckydin geht nicht und telamon ist sowieso schon raus aus dem Rennen...

Auch wenn ich nix großartig da rauslese, aber zum kompilieren brauch ich die schon ...
:slight_smile:

Ich hab die UTFT von rinki dink....aber mit den hardwareeinstellungen von buydisplay, damit rgb auch rgb ist....und alles läuft

Dann ist was faul.
Da ich auf der portablen Installation nur die rinkyDinky habe...

/home/user1/arduino-1.8.19/portable/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -Wall -Wextra -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10819 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -I/home/user1/arduino-1.8.19/hardware/arduino/avr/cores/arduino -I/home/user1/arduino-1.8.19/hardware/arduino/avr/variants/standard -I/home/user1/arduino-1.8.19/portable/sketchbook/libraries/UTFT -I/home/user1/arduino-1.8.19/hardware/arduino/avr/libraries/SPI/src -I/home/user1/arduino-1.8.19/hardware/arduino/avr/libraries/Wire/src /tmp/arduino_build_374850/sketch/scippolino.ino.cpp -o /tmp/arduino_build_374850/sketch/scippolino.ino.cpp.o
scippolino:30:13: error: 'SSD1963_800480' was not declared in this scope
 UTFT myGLCD(SSD1963_800480, 38, 39, 40, 41); //(byte model, int RS, int WR, int CS, int RST, int SER)

Mal sehen, was mir zu morgen dazu einfällt. Im Moment bin ich überfragt.

nimm das 480 weg und es läuft....in der lib ist nur ssd1963_800 drin....das funktioniert aber auch

Hier noch der aktuellste sketch, der funktioniert,,,ausser dass es da random touches gibt....da weiss ich noch nicht, wie ich das entprellen kann. manchmal gibt es auch random touches die eine neue seite aufrufen....warum auch immer

#include <SPI.h>
#include <Wire.h>
#include <UTFT.h>
#include <UTFT_Geometry.h>
#include <Adafruit_FT6206.h>
#include <ADXL345_WE.h> //Gyroskop Bibliothek
#include <EEPROM.h>
#include <BME280I2C.h>
#include "HardwareSerial.h"
#include "icons.h"
#include "victron.h"


// The FT6206 uses hardware I2C (SCL/SDA)
Adafruit_FT6206 ts = Adafruit_FT6206();

#define TFT_CS 20
#define TFT_DC 21
UTFT tft(SSD1963_800, 38, 39, 40, 41); //(byte model, int RS, int WR, int CS, int RST, int SER)
UTFT_Geometry geo(&tft);
#define FT5206_WAKE 11
#define FT5206_INT   48


extern uint8_t SmallFont[];
extern uint8_t BigFont[];
extern uint8_t arial_normal[];
extern uint8_t arial_round[];
extern uint8_t Inconsola[];
extern uint8_t UbuntuBold[];
extern uint8_t various_symbols[];
extern uint8_t Various_Symbols_32x32[];



boolean RecordOn = false;
int offsetX = 30;
int offsetY = 10;


//Programmversion
String Version = "1.2.7";
//Uhr

#include <RTClib.h> //Real Time Clock Bibliothek einbinden

//Uhr definieren
RTC_DS1307 rtc; //Uhr benennen
#define RST_PIN -1 //Reset Pin nicht vorhanden --> also -1

//Temperatursensor definieren
BME280I2C bme;


//Colors
#define BLACK   0x0000
#define GREY    0x5555
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define DARKGREEN   0x05C0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define GOLD    0xDDC0
#define WHITE   0xFFFF
#define DARKGREY 0x10A2

//Temperaturvariablen
float temp(NAN), hum(NAN), pres(NAN), temp_alt, hum_alt, pres_alt;
float hoeheum;

float baro[100];
String tStamp[100];
int b, l1;
static uint32_t baroloop;
float maxValueb, minValueb;
long yPixel, yPixel1, yb, yb1;
int barostatus = 0;
float baroInterval = 0.6; //in minuten 14.4 enspricht 24 stunden - 7.2 entspricht 12 stunden - 0.6 entspricht 1 Stunde - 0.05 entspricht 5 Minuten


//////////////////////////////////////////////////////////////
//TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
//////////////////////////////////////////////////////////////

// Template Funktion größten Wert aus Array ermitteln
template <typename T, size_t size> T maxRead(const T (&arr)[size]) {
  T maxValue {arr[0]};
  for (auto &value : arr) maxValue = max(maxValue, value);
  return maxValue;
}

// Template Funktion kleinsten Wert aus Array ermitteln
template <typename T, size_t size> T minRead(const T (&arr)[size]) {
  T minValue {arr[0]};
  for (auto &value : arr) minValue = min(minValue, value);
  return minValue;
}


//////////////////////////////////////////////////////////////
//TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
//////////////////////////////////////////////////////////////
// Button calibration
int margin = 6;
int btnWidth = 250;
int btnHeight = 60;
int btnY = 200;

// Software variable
bool enable_nuit = false;
int parameter = 50, old_parameter = 50;
const int rotar = 1; //Display Rotation
float rad = 0.0174532925;

int displayY = tft.getDisplayXSize();
int displayX = tft.getDisplayYSize();
int splashCounter = 0;



//Uhrzeitvariablen
String Datumget;
String Uhrget;
String Tagnow;
String Wochentag;
String Datumget_alt;
String Uhrget_alt;
String Tagnow_alt;
String Wochentag_alt;
byte ControllerUhr = 0;
uint32_t tiStamp;
int tiStampMin, tiStampStd;


//Batterien
float Aufbaubatterie, Bordbatterie;

//Wasserstandvariablen
int Wasserstand;
float Wasser;
int Liner = 250;

//Gauge Variablen
#define RED2RED 0
#define GREEN2GREEN  1
#define BLUE2BLUE 2
#define BLUE2RED 3
#define GREEN2RED 4
#define RED2GREEN  5
byte seg = 5; //3 // Segments are 5 degrees wide = 60 segments for 300 degrees
byte inc = 10; //5 // Draw segments every 5 degrees, increase to 10 for segmented ring




//Gyroskop definieren
#define ADXL345_I2CADDR 0x53 // 0x1D if SDO = HIGH
ADXL345_WE myAcc = ADXL345_WE(ADXL345_I2CADDR); //Name des Gyroskops

uint32_t runTime = -99999;       // time for next update



String Voreground, Backbround, Fontcolor;

enum pageId {
  MENU,
  INFO,
  BATTERIE,
  WATER,
  INFO1,
  DISPLAYAUS,
  SOLAR,
  SOLAR1,
  SOLAR2,
  WETTER,
  WETTERTREND,
  EINSTELL,
  EINSTELLFARBE,
  LEVEL,
  SPLASH,
  NEUSTART,
  TIMEOUT,
  WECHSELRICHTER,
};
unsigned int currentPage = MENU, oldPage = -1, aktPage = -1;

//Tonausgabe

int tonPin = 45;

//Solarvariablen
float SolarAmps, SolarAmps2, SolarVolts, BatAmps, BatVolts;
int SolarWatts;
String label200, label160, val200, val160;

String PID200, PID160;         //Produkt-ID
String FW200, FW160;          //Firmware Version
String SER200, SER160;         //Seriennummer
float V200, V160;          //[V]   Batteriespannung
float Ib200, Ib160;          //[mA]  Batterieladestrom
float VPV200, VPV160;        //[V] Solar-Panel Spannung
float PPV200, PPV160;        //[W] Solar-Panel Leistung
int CS200, CS160;          //Charger-Status 0=Aus, 2=Error, 3=Laden, 4=Entladen, 5=Batt V halten
String MPPT200, MPPT160;        //Unbekannter Wert
String OR200, OR160;          //Unbekannter Wert
int ERR200, ERR160;         //Error-Status 0=Kein Error, 2=Batt V zu hoch, 17=Temp zu hoch, 18=Überstrom, 19=Amp umgekehrt, 20=Ladezeitlimit abgelaufen, 21=Amp Sensor Fehler, 26=Anschlüsse überhitzt, 33=Solar V zu hoch, 34=Solar A zu hoch, 38=Input abgeschaltet, 116=WerkseinstellungenDatenVerloren, 117=Falsche Firmware, 119=Einstellungen falsch
float LOAD200, LOAD160;        //Lastausgang ON/OFF
float IL200, IL160;         //[mA] Lastausgang-Strom
float H19200, H19160;        //[kWh] Ertrag über die gesamte Lebensdauer des Gerätes
int H20200, H20160;        //[kWh] Ertrag Heute
int H21200, H21160;        //[W] Max-Leistung Heute
int H22200, H22160;        //[kWh] Ertrag Gestern
int H23200, H23160;        //[W] Max-Leistung Gestern
int HSDS200, HSDS160;            //[T] Anzahl Tage über die gesamte Lebensdauer des Gerätes
float tempfloat = 0.00;
int radius = 70;




//Einstellungen zum Nivelieren
float abwlr = 1.5; //winkelabweichung zum Keilen
float abwhv = 1.5;
float links = 0.0, rechts = 0.0, vorne = 0.0, hinten = 0.0;


//Umrechnung RGB in 565
#define RGB565(r, g, b)    ((((r)& 0xF8) << 8) | (((g) & 0xFC) << 3) | (((b) & 0xF8) >> 3))

//Farbeinstellungen
uint16_t Vorder, BtnTextf, Schriftf, Vorder_alt, BtnTextf_alt, Schriftf_alt;
int selRot, selGruen, selBlau, selRot_alt, selGruen_alt, selBlau_alt;
int  pixel_x_alt;    //Touch_getXY() updates global vars

int o = 0;
int n = 1;
int F = 0;
int rot, gruen, blau, fx, fy, cursx, Vbtn, Tbtn, rf, gf, bf;

//Systemreset
void(* resetFunc) (void) = 0;//declare reset function at address 0

//Bildschirm schwarz
unsigned int aus_ee;
long aus;
static uint32_t sekundenloop, looper, timeoutloop;
int zahl[8], ki = 0, ka = 0;
int uebergabe = 0;

//Wechselrichter
bool wechselrichterStatus = false;


//Buttons
bool down = 0;
bool pressed = 0;

int ty, tx;

void setup(void)
{
  Serial.begin(9600);

  Serial1.begin(19200);
  Serial3.begin(19200);
  aus_ee = EEPROM[0];

  //Grundfarben definieren
  Vorder = 0x0a2a;
  BtnTextf = 0xFFFF;
  Schriftf = 0xf2f0;
  fx = 10;//Position Farbbalken
  fy = 50;
  cursx = 0;
  Vbtn = 0;
  Tbtn = 0;




  tft.InitLCD();
  if (!ts.begin(40)) {
    Serial.println("Unable to start touchscreen.");
  }
  else {
    Serial.println("Touchscreen started.");
  }
  pinMode(8, OUTPUT);
  digitalWrite(8, HIGH);
  pinMode     (FT5206_WAKE, INPUT);
  digitalWrite(FT5206_WAKE, HIGH );

  pinMode     (FT5206_INT, INPUT);
  tft.fillScr(0, 0, 0);
  tft.setFont(SmallFont);



  //Uhr
#ifndef ESP8266 //Wenn ein ESP8266 angeschlossen ist
  while (!Serial); // auf den Seriellen Port warten. Dieser wird für natives USB benötigt
#endif
  delay(500);
  if (! rtc.begin())
  { //Wenn rtc.begin fehlschlägt
    Serial.println("Konnte die RTC nicht starten"); //Ausgabe auf den seriellen Monitor
    Serial.flush(); //Seriellen Monitor leeren
    abort(); //abbrechen
  }
  delay(1000); //1 Sekunde warten
  if (! rtc.isrunning())
  { //Wenn RTC nicht läuft
    //Serial.println("RTC läuft nicht, also müssen wir die Zeit einstellen");
    //rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); //Daten von Systemzeit holen
    // rtc.adjust(DateTime(2023, 6, 23, 18, 7, 30)); //Datum und Uhrzeit manuell eingeben (ohne anführende Nullen
  }
  // Wenn nur Zeit/Datum eingestellt werden muss
  //rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); //Daten von Systemzeit holen
  // rtc.adjust(DateTime(2023, 6, 23, 18, 7, 30)); //Datum und Uhrzeit manuell eingeben (ohne anführende Nullen
  getUhrzeit();


  //Gyroskop abfragen
  if (!myAcc.init()) {
    Serial.println("ADXL345 not connected!");
  }
  //Korrekturfaktoren für das Gyroskop
  myAcc.setCorrFactors(-262.0, 279.0, -270.0, 275.0, -291.0, 214.0);

  //Gyroskop ausrichten
  delay(2000);
  myAcc.measureAngleOffsets();

  //Gyroskop Abtastrate
  myAcc.setDataRate(ADXL345_DATA_RATE_50);

  //Gyroskop Messbereich
  myAcc.setRange(ADXL345_RANGE_2G);


  // Temperatursensor starten
  while (!bme.begin())
  {
    Serial.println("Could not find BME280 sensor!");
    delay(1000);
  }
  switch (bme.chipModel())
  {
    case BME280::ChipModel_BME280:
      Serial.println("Found BME280 sensor! Success.");
      break;
    default:
      Serial.println("Found UNKNOWN sensor! Error!");
  }

  //Wire starten
  Wire.begin();
  Wire.setClock(400000L);

  //Wasserstand holen
  getWasser();



  currentPage = SPLASH;
  sekundenloop = millis();
  baroloop = millis();
  timeoutloop = millis();
  wechselrichterStatus = 1;
  label200 = "0";
  label160 = "0";
  b = 99;
  Serial.println(displayX);
  Serial.println(displayY);
  Serial.println("Setup fertig");
  tx = 0;
  ty = 0;
  down = 0;
  !ts.touched();
}

void loop(void)
{
  //Serial.println(millis() / 10000 - timeoutloop / 10000);
   Serial.println(pres / 100 + 98.4 - hoeheum);
  if (millis() - baroloop > baroInterval * 60000)
  {
    getBaroTrend();
    //  getUhrzeit();
    baroloop = millis();
  }

  if ((millis() / 10000) - (timeoutloop / 10000)  < aus_ee)
  {
    switch (currentPage)
    {
      case WETTERTREND:
        if (currentPage != oldPage)     drawWetterTrendScreen();
        zbp(WETTER);
        hbp();
        break;

      case SPLASH:
        if (currentPage != oldPage) drawSplashScreen();
        // getSolar200();
        // getSolar160();
        splashCounter++;
        //showSolar160();
        //showSolar200();
        //Serial.print("Counter ");
        //Serial.println(splashCounter);
        if (splashCounter == 100)
        {
          down = 0;
          currentPage = MENU;
        }
        sekundenloop = millis();
        break;

      case MENU: //Menu page
        if (currentPage != oldPage)   drawMenuScreen();
        getTouched();
        // Serial.print("Pressed: ");
        //  Serial.println(pressed);
        if ((down == 1) and (tx > 250 - btnWidth) and (ty > 100 - btnHeight) and (tx < 250 + btnWidth / 2) and (ty < 100 + btnHeight / 2))
        {
          currentPage = WATER;
          down = 0;
        }
        if ((down == 1) and (tx > 550 - btnWidth) and (ty > 100 - btnHeight) and (tx < 550 + btnWidth / 2) and (ty < 100 + btnHeight / 2))
        {
          currentPage = LEVEL;
          down = 0;
        }
        if ((down == 1) and (tx > 250 - btnWidth) and (ty > 205 - btnHeight) and (tx < 250 + btnWidth / 2) and (ty < 205 + btnHeight / 2))
        {
          currentPage = BATTERIE;
          down = 0;
        }
        if ((down == 1) and (tx > 550 - btnWidth) and (ty > 205 - btnHeight) and (tx < 550 + btnWidth / 2) and (ty < 205 + btnHeight / 2))
        {
          currentPage = WETTER;
          down = 0;
        }
        if ((down == 1) and (tx > 250 - btnWidth) and (ty > 310 - btnHeight) and (tx < 250 + btnWidth / 2) and (ty < 310 + btnHeight / 2))
        {
          currentPage = SOLAR;
          down = 0;
        }
        if ((down == 1) and (tx > 550 - btnWidth) and (ty > 310 - btnHeight) and (tx < 550 + btnWidth / 2) and (ty < 310 + btnHeight / 2))
        {
          currentPage = WECHSELRICHTER;
          down = 0;
        }
        ibp();
        sbp();
        break;

      case WATER: //Wasserstand
        if (currentPage != oldPage)   drawWaterScreen();
        updateWater();
        hbp();
        break;

      case LEVEL:
        if (currentPage != oldPage)   drawLevelScreen();
        getLevel();
        hbp();
        break;

      case SOLAR: //Solar 160W

        if (currentPage != oldPage)

          drawSolarScreen();


        //updateSolarScreen();
        hbp();
        vbp(SOLAR1);
        break;

      case SOLAR1: //Solar 200 W

        if (currentPage != oldPage)   drawSolar1Screen();
        updateSolarWerte();
        hbp();
        vbp(SOLAR2);
        zbp(SOLAR);
        break;

      case SOLAR2: //Batterie
        if (currentPage != oldPage)   drawSolar2Screen();

        hbp();
        zbp(SOLAR1);
        break;

      case WETTER:
        if (currentPage != oldPage)
        {
          getTemperatur();
          getUhrzeit();
          drawWetterScreen();
        }
        updateUhrzeit();
        // updateTemperatur();
        hbp();

        vbp(WETTERTREND);
        break;

      case INFO:
        if (currentPage != oldPage) drawInfoScreen();
        if (down == 1)
        {
          currentPage = MENU;
          down = 0;
        }

        break;

      case EINSTELL:
        if (currentPage != oldPage) drawEinstellScreen();

        if ((down == 1) and (tx > 250 - btnWidth) and (ty > 100 - btnHeight) and (tx < 250 + btnWidth / 2) and (ty < 100 + btnHeight / 2))
        {
          currentPage = NEUSTART;
          down = 0;
        }
        if ((down == 1) and (tx > 250 - btnWidth) and (ty > 205 - btnHeight) and (tx < 250 + btnWidth / 2) and (ty < 205 + btnHeight / 2))
        {
          currentPage = TIMEOUT;
          down = 0;
        }

        if ((down == 1) and (tx > 250 - btnWidth) and (ty > 310 - btnHeight) and (tx < 250 + btnWidth / 2) and (ty < 310 + btnHeight / 2))
        {
          currentPage = EINSTELLFARBE;
          down = 0;
        }

        hbp();
        break;

      case EINSTELLFARBE:
        if (currentPage != oldPage) drawEinstellFarbeScreen();
        //Touch_getXY();
        Farbenwahl();

        zbp(EINSTELL);
        hbp();
        break;

      case BATTERIE:
        if (currentPage != oldPage)   drawBatterieScreen();
        updateBatterie();
        hbp();
        break;

      case NEUSTART: //System zurücksetzen
        if (currentPage != oldPage)   drawResetScreen();


        if ((down == 1) and (tx > 225) and (ty > displayY - 42) and (tx < 275) and (ty < displayY - 2))
        {
          down = 0;
          resetFunc();
        }

        //        checkBtn (displayX / 2 + 200, 400, 200, 200, 1, 1, "");
        if ((down == 1) and (tx > 525) and (ty > displayY - 42) and (tx < 675) and (ty < displayY - 2))
        {
          currentPage = EINSTELL;
          down = 0;
        }
        break;

      case DISPLAYAUS:
        if (currentPage != oldPage)drawDisplayAusScreen();
        getTouched();
        if (down == 1)
        {
          digitalWrite(8, HIGH);
          //       currentPage = aktPage;
          down = 0;
        }

        break;

      case TIMEOUT:
        if (currentPage != oldPage)drawTimeoutScreen();

        tft.setColor(Schriftf);
        tft.setBackColor(0x0000);
        tft.setFont(arial_round);


        if ((down == 1) and (tx > 480) and (ty > displayY - 42) and (tx < 600) and (ty < displayY - 2))
        {
          down = 0;
          if (aus_ee < 60) tft.print("   ", 350, 70);
          aus_ee = aus_ee + 1;
          tft.printNumI(aus_ee * 10, 350, 70);
          if (aus_ee >= 60)
          {
            aus_ee = 60;
            tft.print("Mehr als 10 Minuten macht keinen Sinn", 20, 90);
            tft.print(aus_ee * 10, 350, 70);

          }
          delay(300);
        }

        if ((down == 1) and (tx > 200) and (ty > displayY - 42) and (tx < 320) and (ty < displayY - 2))
        {
          down = 0;
          if (aus_ee > 0) tft.print("   ", 350, 70);
          aus_ee = aus_ee - 1;
          tft.printNumI(aus_ee * 10, 350, 70);
          if (aus_ee  <= 12)
          {
            aus_ee = 12;
            tft.print("Weniger als 2 Minuten ist nicht erlaubt", 20, 90);
            tft.printNumI(aus_ee * 10, 350, 70);

          }
          delay(300);
        }


        if ((down == 1) and (tx > 340) and (ty > displayY - 42) and (tx < 460) and (ty < displayY - 2))

        {
          down = 0;

          EEPROM.update(0, aus_ee);
          ////Serial.print("Ew");
          ////Serial.println(aus_ee);

          delay(10);
          currentPage = EINSTELL;
        }
        hbp();
        break;


      case WECHSELRICHTER:
        if (currentPage != oldPage)drawWechselrichterScreen();
        getTouched();
        if ((down == 1) and (tx > 540) and (ty > 230) and (tx < 660) and (ty < 270))
        {
          if (wechselrichterStatus == 0)
          {


            wechselrichterStatus = 1;
            drawSwitch(50, 100, 300, 20, Vorder, wechselrichterStatus);
            pressed = 0;
          }
        }

        if ((down == 1) and (tx > 140) and (ty > 230) and (tx < 260) and (ty < 270))
        {
          if ((wechselrichterStatus == 1))
          {

            wechselrichterStatus = 0;
            drawSwitch(50, 100, 300, 20, Vorder, wechselrichterStatus);
            pressed = 0;
          }
        }
        hbp();
        break;
    }
    if (oldPage == currentPage)
    {
      getTouched();
      if (digitalRead(8) == LOW and down == 1)
      {
        down = 0;
        digitalWrite(8, HIGH);
      }

    }
    else
    {
      down = 0;
      timeoutloop = millis();
    }
  }
  else if (millis() - sekundenloop  > aus_ee)
  {
    //  currentPage = DISPLAYAUS;
    digitalWrite(8, LOW);
    timeoutloop = millis();
  }
}


/************************************************************************************
  Screens gestalten
************************************************************************************/
void drawWechselrichterScreen()
{
  down = 0;
  tft.clrScr();

  tft.setColor(Schriftf);
  tft.setBackColor(0x0000);
  tft.setFont(arial_round);

  tft.print("Wechselrichter",  20, 5);
  tft.drawLine(0, 34,  displayX * 0.6, 34);
  drawSwitch(50, 100, 300, 20, Vorder, wechselrichterStatus);
  tft.setColor(Schriftf);
  tft.print("Aus", 0, 100 - tft.getFontYsize() / 2);
  tft.print("Ein", 355, 100 - tft.getFontYsize() / 2);
  Button(600, 250, 120, 40, Vorder, BtnTextf, "AN", UbuntuBold);
  Button(200, 250, 120, 40, Vorder, BtnTextf, "AUS", UbuntuBold);
  showHome();
  oldPage = currentPage;
}


void drawSplashScreen()
{
  down = 0;
  tft.clrScr();
  tft.setColor(Vorder);
  tft.drawBitmap(displayX / 2 - 250, displayY / 2 - 65, 250, 65, rimor, 2);
  // tft.drawBitmap(displayX / 2, displayY / 2, 120, 60, sailer);
  oldPage = currentPage;
}


void drawTimeoutScreen()
{
  down = 0;

  tft.clrScr();

  tft.setColor(Schriftf);
  tft.setBackColor(0x0000);
  tft.setFont(arial_round);

  tft.print("Timeout fur das Display",  20, 5);
  tft.drawLine(0, 34,  displayX * 0.6, 34);
  tft.print ("Timeout in Sekunden: ", 20, 70);
  tft.printNumI(aus_ee * 10, 350, 70);
  Button(260, displayY - 22, 120, 40, Vorder, BtnTextf, "-10", UbuntuBold);
  Button(540, displayY - 22, 120, 40, Vorder, BtnTextf, "+10", UbuntuBold);
  Button(displayX / 2, displayY - 22, 120, 40, Vorder, BtnTextf, "OK", UbuntuBold);
  aus_ee = EEPROM[0];
  showHome();
  oldPage = currentPage;
}


void drawDisplayAusScreen()
{
  down = 0;
  digitalWrite(8, LOW);
  // tft.fillScr(0x0000);
  aktPage = oldPage;
  oldPage = currentPage;
}


void drawMenuScreen()
{
  down = 0;
  tx = 0;
  ty = 0;
  tft.clrScr();
  tft.setColor(Schriftf);
  tft.setBackColor(0x0000);
  tft.setFont(arial_round);

  tft.print("Womo - Monitor",  20, 5);
  tft.drawLine(0, 34,  displayX * 0.6, 34);
  // Button
  tft.setColor(Vorder);
  // tft.drawBitmap(displayX - 40, 10, 32, 32, INFOICON);
  // tft.drawBitmap(displayX - 80, 10, 32, 32, SETT);

  Button(250, 100, btnWidth, btnHeight, Vorder, BtnTextf, "Wasser", UbuntuBold);
  Button(550, 100, btnWidth, btnHeight, Vorder, BtnTextf, "Level", UbuntuBold);
  Button(250, 205, btnWidth, btnHeight, Vorder, BtnTextf, "Batterie", UbuntuBold);
  Button(550, 205, btnWidth, btnHeight, Vorder, BtnTextf, "Wetter", UbuntuBold);
  Button(250, 310, btnWidth, btnHeight, Vorder, BtnTextf, "Solar", UbuntuBold);
  Button(550, 310, btnWidth, btnHeight, Vorder, BtnTextf, "Strom", UbuntuBold);
  showInfo();
  showSet();
  oldPage = currentPage;
}


void drawBatterieScreen()
{
  down = 0;

  tft.clrScr();
  tft.setColor(Schriftf);
  tft.setBackColor(0x0000);
  tft.setFont(arial_round);

  tft.print("Ladezustand Batterien",  20, 5);
  tft.drawLine(0, 34,  displayX * 0.6, 34);

  //Aufbaubatterie
  getAufbaubatterie();
  getBordbatterie();
  int radius = 70;
  tft.print("Aufbaubatterie", 48, 70);

  tft.printNumF(V200, 2, 80, 135);
  tft.print(" V", 140, 153);
  ringMeter(V200, 11.6, 14.4, 120 - radius, 160 - radius, radius, RED2GREEN  );
  //Bordbatterie
  tft.print("Bordbatterie", 298, 70);
  tft.printNumF(Bordbatterie / 100, 2, 320, 153);
  tft.print(" V", 380, 153);
  ringMeter(Bordbatterie, 1100, 1500, 360 - radius, 160 - radius, radius, RED2GREEN  );

  showHome();
  oldPage = currentPage;
}


void drawSolarScreen()//Solar gesamt
{
  down = 0;

  for (int r = 0; r < 10; r++)
  {
    getSolar200();
    getSolar160();
  }

  tft.clrScr();
  tft.setColor(Schriftf);
  tft.setBackColor(0x0000);
  tft.setFont(arial_round);

  tft.print("Solarleistung gesamt",  20, 5);
  tft.drawLine(0, 34,  displayX * 0.6, 34);

  //Volts
  tft.printNumF((VPV200 + VPV160) / 2, 2, 50, 167 - 14);
  tft.print(" V", 110, 167 - 14);
  ringMeter((VPV200 + VPV160) / 2, 12, 45, 120 - radius - 30, 160 - radius, radius, RED2GREEN  );
  //Amps
  tft.printNumF(((PPV200 + PPV160) / (VPV200 + VPV160) / 2), 2, 200, 167 - 14);
  tft.print(" A", 260, 167 - 14);
  ringMeter((PPV200 + PPV160) / (VPV200 + VPV160) / 2, 0, 20, 240 - radius, 160 - radius, radius, RED2GREEN  );
  //Watts
  tft.printNumF((PPV200 + PPV160), 0, 361, 167 - 14);
  tft.print(" W", 398, 167 - 14);
  ringMeter(PPV200 + PPV160, 1, 360, 360 - radius + 30, 160 - radius, radius, RED2GREEN  );

  showHome();
  showVor();
  oldPage = currentPage;
}


void drawSolar1Screen()
{
  down = 0;
  getSolar200();
  getSolar160();

  tft.clrScr();
  tft.setColor(Schriftf);
  tft.setBackColor(0x0000);
  tft.setFont(arial_round);

  tft.print("Solarwerte",  20, 5);
  tft.drawLine(0, 34,  displayX * 0.6, 34);


  tft.print("Bat. Spannung: ", 20, 50);
  tft.printNumF(V200, 2, 280, 50);

  tft.print(" V", 365, 50);

  tft.print("Ladestrom: ", 20, 70);

  tft.printNumF(Ib200 + Ib160, 2, 280, 70);
  tft.print(" A", 365, 70);
  tft.print("Tot. Ertrag: ", 20, 90);
  tft.printNumF(H19200 + H19160, 2, 280, 90);
  tft.print(" kWh", 365, 90);

  tft.print("Ertrag heute: ", 20, 110);
  tft.printNumF(H20200 + H20160, 2, 280, 110);

  tft.print(" Wh", 365, 110);
  tft.print("max Leistung heute: ", 20, 130);

  tft.printNumF(H21200 + H21160, 2, 280, 130);

  tft.print(" W", 365, 130);

  tft.print("Ertrag gestern: ", 20, 150);
  tft.printNumF(H22200 + H22160, 2, 280, 150);
  tft.print(" Wh", 365, 150);

  tft.print("max Leistung gestern: ", 20, 170);
  tft.printNumF(H23200 + H23160, 2, 280, 170);
  tft.print(" W", 365, 170);
  showHome();
  showVor();
  showZuruck();
  oldPage = currentPage;
}


void drawSolar2Screen()
{
  down = 0;

  showHome();
  showZuruck();
  oldPage = currentPage;
}


void drawWaterScreen()
{
  down = 0;
  tft.clrScr();
  tft.setColor(Schriftf);
  tft.setBackColor(0x0000);
  tft.setFont(arial_round);

  tft.print("Frischwasser",  20, 5);
  tft.drawLine(0, 34,  displayX * 0.6, 34);
  randomSeed(millis());
  Wasserstand = random(0, 220);
  getWasser();
  showHome();
  oldPage = currentPage;
}


void drawLevelScreen()
{
  down = 0;
  tft.fillScr(0x0000);
  tft.setColor(Schriftf);
  tft.setBackColor(0x0000);
  tft.setFont(arial_round);
  tft.print("Nivelierung",  20, 5);
  tft.drawLine(0, 34,  displayX * 0.6, 34);

  getLevel();
  tft.setColor(WHITE);
  tft.drawRect(10, 100, 70, 120);
  tft.drawRect(10, 250, 70, 270);
  tft.drawRect(300, 100, 360, 120);
  tft.drawRect(300, 250, 360, 270);
  tft.drawLine(40, 120, 40, 175);
  tft.drawLine(40, 195, 40, 250);
  tft.drawCircle(40, 185, 10);
  tft.drawLine(330, 120, 330, 250);
  tft.drawLine(50, 185, 330, 185);
  showHome();
  oldPage = currentPage;
}


void drawInfoScreen()
{
  down = 0;
  tft.clrScr();
  tft.setColor(Schriftf);
  tft.setBackColor(0x0000);
  tft.setFont(arial_round);
  tft.print("Informationen",  20, 5);
  tft.drawLine(0, 34,  displayX * 0.6, 34);
  tft.print("Dieses System wurde in m", 25, 80);
  tft.print(0x81, 300, 80);
  tft.print("hevoller", 310, 80);
  tft.print("Kleinstarbeit und mit viel Zeit", 25, 105);
  tft.print("von Roland zusammengekl", 25, 130);
  tft.print(0x94, 25, 300);
  tft.print("ppelt.", 25, 310);
  tft.print("Bei Fragen gerne melden.", 25, 155);
  tft.print("Tel: +41 79 XXX XX XX", 25, 205);
  tft.print("email: rxxxxxxxxx@gmail.com", 25, 230);
  tft.print("Programmversion: ", 25, 280);
  tft.print(Version, 250, 280);
  // tft.print(0xE0);
  down = 0;
  oldPage = currentPage;
}


void drawEinstellScreen()
{
  down = 0;

  tft.clrScr();//(100, 155, 203)
  tft.setColor(Schriftf);
  tft.setBackColor(0x0000);
  tft.setFont(arial_round);
  tft.print("Einstellungen",  20, 5);
  tft.drawLine(0, 34,  displayX * 0.6, 34);
  Button(250, 100, btnWidth, btnHeight, Vorder, BtnTextf, "Neustart", UbuntuBold);
  Button(250, 205, btnWidth, btnHeight, Vorder, BtnTextf, "Display", UbuntuBold);
  Button(250, 310, btnWidth, btnHeight, Vorder, BtnTextf, "Farben", UbuntuBold);
  showHome();
  showVor();
  oldPage = currentPage;
}


void drawEinstellFarbeScreen()
{
  down = 0;
  tft.clrScr();

  Button(10, 250, 150, 20, Vorder, BtnTextf, "Hauptfarbe", UbuntuBold);
  Button(330, 250, 150, 20, Vorder, BtnTextf, "BtnTextfarbe", UbuntuBold);
  Button(330, 300, 100, 20,  Vorder, BtnTextf, "OK", UbuntuBold);
  drawSlider(40, 100, 255, 10, 40, Vorder, BtnTextf);
  tft.setColor(Schriftf);
  tft.setBackColor(0x0000);
  tft.setFont(arial_round);

  tft.print("Farbeinstellungen",  20, 5);
  tft.drawLine(0, 34,  displayX * 0.6, 34);
  showHome();
  showZuruck();
  oldPage = currentPage;
}


void drawWetterScreen()
{
  down = 0;
  Serial.println(pres / 100 + 98.4);
  Serial.println(pres);
  Serial.println(hoeheum);


  tft.clrScr();//(100, 155, 203)
  tft.setFont(arial_round);
  tft.print("Heute ist: ", 50, 50);
  tft.print(Wochentag, 330, 50);
  ////Serial.println(Wochentag);
  ////Serial.println(Tagnow);
  tft.print(Datumget, 330, 75);
  ////Serial.println(Datumget);
  tft.print(Uhrget, 330, 100);
  ////Serial.println(Uhrget);
  Uhrget_alt = Uhrget;
  Datumget_alt = Datumget;
  Tagnow_alt = Tagnow;

  tft.setFont(arial_round);
  tft.print("Temperatur:          ", 50, 150);
  tft.printNumF(temp, 1, 361, 150);
  // tft.print(0xF7, 340, 150);
  tft.print(" C ", 440, 150);
  tft.print("Luftfeuchtigkeit:    ", 50, 175);
  tft.printNumF(hum, 1, 361, 175);
  tft.print(" % ", 440, 175);
  tft.print("Luftdruck: ", 50, 200);
  tft.printNumF(pres / 100 + 98.4, 2, 329, 200);
  tft.print(" hpa ", 440, 200);
  if (pres / 100 + 98.4 - hoeheum >= 75 and pres / 100 + 98.4 - hoeheum <= 88)
  {
    tft.print("Tendenz: Regen", 50, 250);
  }
  if (pres / 100 + 98.4 - hoeheum >= 89 and pres / 100 + 98.4 - hoeheum <= 108)
  {
    tft.print("Tendenz: Wechselhaft", 50, 250);
  }
  if (pres / 100 + 98.4 - hoeheum >= 109 and pres / 100 + 98.4 - hoeheum <= 129)
  {
    tft.print("Tendenz: Schön", 50, 250);
  }
  if (pres / 100 + 98.4 - hoeheum >= 130)
  {

    tft.print("Tendenz: Trocken", 50, 250);
  }
  showHome();
  showVor();
  oldPage = currentPage;
}


////////////////////////////////////////////////////////////////////
//WetterTrend
////////////////////////////////////////////////////////////////////
void drawWetterTrendScreen()
{
  down = 0;
  for (int l1 = 0; l1 < (sizeof(baro) / sizeof(baro[0])); l1++)
  {
    maxValueb = maxRead(baro);
    minValueb = minRead(baro);
  }

  tft.clrScr();//(100, 155, 203)
  tft.setColor(Vorder);
  tft.setFont(SmallFont);
  tft.drawLine(59, 50, 59, 350);
  tft.drawLine(59, 350, 761, 350);
  tft.printNumF(maxValueb / 100, 2, 0, 50 - (tft.getFontYsize() / 2));
  tft.printNumF(minValueb / 100, 2, 0, 350 - (tft.getFontYsize() / 2));
  int calc = 1;
  for (int posi = 10; posi >= 1; posi--)
  {


    Serial.print ("Diff: ");
    Serial.println(tiStamp - (tiStamp - (calc * 1 * 60 * baroInterval)));
    timeStamp(tiStamp, tiStamp - (calc * 10 * 60 * baroInterval));
    String Std, Min, Stempel;
    if (tiStampStd < 10)
    {
      Std = String(tiStampStd);
      Std = "0" + Std;
    }
    else
    {
      Std = String(tiStampStd);
    }
    if (tiStampMin < 10)
    {
      Min = String(tiStampMin);
      Min = "0" + Min;
    }
    else
    {
      Min = String(tiStampMin);
    }
    Stempel = (Std + ":" + Min);
    tft.print(Stempel, (59 - tft.getFontYsize() / 2) + (posi - 1) * 77, 400, 270);
    Serial.print("Pos: ");
    Serial.println((59 - tft.getFontYsize() / 2) + ((posi - 1) * 77));
    calc++;
  }
  l1 = 0;
  while (l1 < 99)
  {
    yb = baro[l1];
    yPixel = map(yb, minValueb, maxValueb, 349, 50);
    // Serial.print("Yb: ");
    // Serial.println(yPixel);
    yb1 = baro[l1 + 1];
    yPixel1 = map(yb1, minValueb, maxValueb, 349, 50);
    //  Serial.print("Yb1: ");
    //  Serial.println(yPixel1);
    tft.setColor(Schriftf);
    tft.drawLine(l1 * 7 + 60, yPixel, l1 * 7 + 67, yPixel1);
    //tft.setCursor(200, 160);
    //tft.print(baro[l]);
    l1++;
  }
  // tft.setColor(Vorder);
  // tft.drawLine(b + 52, 50, b + 52, 451);
  showHome();

  showZuruck();
  oldPage = currentPage;
}


void drawResetScreen()
{
  down = 0;
  tft.clrScr();
  tft.setColor(Schriftf);
  tft.setBackColor(0x0000);
  tft.setFont(arial_round);

  tft.print("Neustart",  20, 5);
  tft.drawLine(0, 34,  displayX * 0.6, 34);
  tft.setFont(arial_round);

  tft.print("Bei einem Neustart des Systems", 25, 70);
  tft.print("werden alle Parameter neu geladen.", 25, 95);
  tft.print("Das Fahrzeug muss dabei ganz", 25, 120);

  tft.print("gerade stehen, da der Niveausensor", 25, 145);

  tft.print("dabei neu kalibriert wird.", 25, 170);
  tft.print("Neu starten ? ", 25, 220);

  Button(200, displayY - 42, 120, 40, Vorder, BtnTextf, "JA", UbuntuBold);
  Button(600, displayY - 42, 120, 40, Vorder, BtnTextf, "NEIN", UbuntuBold);

  oldPage = currentPage;
}


/************************************************************************************
  Zusätzliche Funktionen
*************************************************************************************/

//#######################################################
//Fest platzierte Buttons
//#######################################################
void showHome()//Home Button anzeigen
{
  //  tft.drawBitmap(20,  displayY - 34, 32, 32, HOMEP);
  Button(70, displayY - 22, 120, 40, Vorder, WHITE, "Home", UbuntuBold);
}


void hbp() //home Button pressed
{
  getTouched();
  if (down == 1)
  {
    if ((tx > 10) and (ty > displayY - 42) and (tx < 130) and (ty < displayY - 2))
    {
      currentPage = MENU;
      down = 0;
    }
  }
}


void showVor()//Vorwärts Button anzeigen

{
  Button(465, displayY - 22, 120, 40, Vorder, WHITE, "S", Various_Symbols_32x32);
}



void vbp(unsigned int Page) //Vorwärts Button gedrückt
{
  getTouched();
  if (down == 1)
  {
    if ((tx > 405) and (ty > displayY - 42) and (tx < 525) and (ty < displayY - 2))
    {
      currentPage = Page;
      down = 0;
    }
  }
}

void showZuruck()//Zurück Button anzeigen
{
  Button(335, displayY - 22, 120, 40, Vorder, WHITE, "R", Various_Symbols_32x32);
}


void zbp(unsigned int Page) //Zurück Button pressed
{
  getTouched();
  if (down == 1)
  {
    if ((tx > 275) and (ty > displayY - 42) and (tx < 355) and (ty < displayY - 2))
    {
      currentPage = Page;
      down = 0;
    }
  }
}


void showInfo()//info Button anzeigen
{
  Button(displayX - 26, 26, 50, 50, 0x0000, WHITE, "i", UbuntuBold);
}


void ibp() //Info Button gedrückt
{
  getTouched();
  if (down == 1)
  {
    if ((tx < displayX - 1) and (ty > 1) and (tx > displayX - 52) and (ty < 52))
    {
      currentPage = INFO;
      down = 0;
    }
  }
}

void showSet()//Settings Button anzeigen
{
  Button(displayX - 86, 26, 50, 50, 0x0000, WHITE, "", UbuntuBold);
  tft.drawBitmap(displayX - 111 + 9, 1 + 9, 32, 32, SETT);

}


void sbp() //Settings Button gedrückt
{
  getTouched();
  if (down == 1)
  {
    if ((tx < displayX - 61) and (ty > 1) and (tx > displayX - 101) and (ty < 52))
    {
      currentPage = EINSTELL;
      down = 0;
    }
  }
}






//##############################################
//#Uhrzeit auslesen
//##############################################
void getUhrzeit()
{
  vbp(WETTERTREND);
  hbp();
  DateTime now = rtc.now(); //Daten auslesen
  char buf1[] = " DDD"; //Wochentag in buf2[] schreiben
  Tagnow = (now.toString(buf1)); //Wochentag als String übergeben an tagnow
  //Überprüfung welcher Wochentag ist, und diesen dann ausgeschrieben an Display senden mit Zeilenumbruch
  if (Tagnow == " Sam") Wochentag = "Samstag";
  else if (Tagnow == " Son") Wochentag = "Sonntag";
  else if (Tagnow == " Mon") Wochentag = "Montag";
  else if (Tagnow == " Die") Wochentag = "Dienstag";
  else if (Tagnow == " Mit") Wochentag = "Mittwoch";
  else if (Tagnow == " Don") Wochentag = "Donnerstag";
  else if (Tagnow == " Fre") Wochentag = "Freitag";
  //Überprüfung fertig
  char buf2[] = "DD.MM.YYYY";
  Datumget = (now.toString(buf2));
  char buf3[] = "hh:mm";
  Uhrget = (now.toString(buf3)); //Aktuelle Uhrzeit in oledreset schreiben
  tiStamp = now.unixtime();

}


//##############################################
//#Uhrzeit aktualisieren
//##############################################
void updateUhrzeit()
{

  getUhrzeit();
  if (Uhrget != Uhrget_alt or Datumget != Datumget_alt or Tagnow != Tagnow_alt)
  {
    ////Serial.println("void UpdateUhrzeit");
    tft.setFont(arial_round);
    tft.print(Wochentag, 330, 50);
    ////Serial.println(Wochentag);
    ////Serial.println(Tagnow);

    tft.print(Datumget, 330, 75);
    ////Serial.println(Datumget);
    tft.print(Uhrget, 330, 100);
    ////Serial.println(Uhrget);
    Uhrget_alt = Uhrget;
    Datumget_alt = Datumget;
    Tagnow_alt = Tagnow;
  }
}

void timeStamp(uint32_t zeit1, uint32_t zeit2) // Danke an Tommy56
{
  DateTime now = rtc.now(); //Daten auslesen
  uint32_t diff;
  uint8_t sec, mi, hr;
  if (zeit1 > zeit2) diff = zeit1 - zeit2;
  else diff = zeit2 - zeit1;
  sec = diff % 60;
  diff /= 60;
  tiStampMin = diff % 60;
  diff /= 60;
  tiStampStd = diff % 24;
  diff /= 24;
  if (now.hour() - tiStampStd < 0)
  {
    tiStampStd = (24 - tiStampStd);
  }
  else
  {
    tiStampStd = (now.hour() - tiStampStd);
  }
  if (now.minute() - tiStampMin < 0)
  {
    tiStampMin = (60 - tiStampMin);
    tiStampStd = (tiStampStd - 1);
  }
  else
  {
    tiStampMin = now.minute() - tiStampMin;
  }

}






//##############################################
//#Temperatursensor auswerten
//##############################################
void getTemperatur()
{
  // Temperaturmessung dht
  BME280::TempUnit tempUnit(BME280::TempUnit_Celsius);
  BME280::PresUnit presUnit(BME280::PresUnit_Pa);
  bme.read(pres, temp, hum, tempUnit, presUnit);
  hoeheum = (1013.25 * pow((1 - 6.5 * 867 / (288150)), 5.255));

}

//##############################################
//#Temperatursensor updaten
//##############################################
void updateTemperatur()
{
  //
  getTemperatur();
  tft.setFont(arial_round);
  if (pres != pres_alt)
  {
    tft.printNumF(pres / 100 + 98.4, 2, 329, 200);
    // tft.print("hpa", 440, 200);
    pres_alt = pres / 100 + 98.4;

  }
  if ((temp, 0) != (temp_alt, 0))
  {
    tft.printNumF(temp, 1, 361, 150);
    //  tft.print(0xF7, 320, 150);
    //  tft.print("C", 300, 150);
    temp_alt = (temp, 0);

  }
  if ((hum, 0) / 100 != (hum_alt, 0))
  {
    tft.printNumF(hum, 1, 361, 175);
    // tft.print(" % ", 300, 175);

    tft.print("Luftdruck : ", 50, 200);
    hum_alt = (hum, 0) / 100;

  }
  if (pres / 100 + 98.4 - hoeheum <= 74)
  {
    tft.print("Tendenz : Sturm", 50, 250);
  }
  if (pres / 100 + 98.4 - hoeheum >= 75 and pres / 100 + 98.4 - hoeheum <= 88)
  {
    tft.print("Tendenz : Regen", 50, 250);
  }
  if (pres / 100 + 98.4 - hoeheum >= 89 and pres / 100 + 98.4 - hoeheum <= 113)
  {
    tft.print("Tendenz : Wechselhaft", 50, 250);
  }
  if (pres / 100 + 98.4 - hoeheum >= 114 and pres / 100 + 98.4 - hoeheum <= 129)
  {
    tft.print("Tendenz : Schön", 50, 250);
  }
  if (pres / 100 + 98.4 - hoeheum >= 130)
  {
    tft.print("Tendenz : Trocken", 50, 250);
  }
}

//##############################################
//#Vorläufige Werte für diverse Sensoren
//##############################################

void getWasser()
{
  Wasserstand = (Wasserstand / 1000 * 45.45);
}

void updateWater()
{
  if (Wasserstand < 100)
  {
    Wasserstand++;
    int radius = 200;
    ringMeter(Wasserstand, 0, 100,  displayX / 2 - radius,  displayY / 2 - radius, radius, 5);

    tft.setFont(UbuntuBold);
    tft.setColor(Schriftf);
    String Wasser = String(Wasserstand);
    int laengeText = Wasser.length() * tft.getFontXsize() / 2;
    tft.print(Wasser, displayX / 2 - laengeText , displayY / 2);
    tft.print("% ", displayX / 2 + 40, displayY / 2);
    //  }
    //sekundenloop = millis();
  }

}


void getAufbaubatterie()
{
  randomSeed(millis());
  Aufbaubatterie = random(1180, 1480);
  ////Serial.println("Aufbaubatterie : " + String(Aufbaubatterie));
}


void getBordbatterie()
{
  randomSeed(millis());
  Bordbatterie = random(1200, 1400);
  ////Serial.println("Bordbatterie : " + String(Bordbatterie));
}




//#######################################################
//Ringmeter
//#######################################################

int ringMeter(int value, int vmin, int vmax, int x, int y, int r, byte scheme)
{
  // Minimum value of r is about 52 before value text intrudes on ring
  // drawing the text first is an option

  x += r; y += r;   // Calculate coords of centre of ring

  int w = r / 4;    // Width of outer ring is 1/4 of radius
  int angle = 150;  // Half the sweep angle of meter (300 degrees)
  int text_colour = 0; // To hold the text colour
  int v = map(value, vmin, vmax, -angle, angle); // Map the value to an angle v


  // Draw colour blocks every inc degrees
  for (int i = -angle; i < angle; i += inc) {

    // Choose colour from scheme
    int colour = 0;
    switch (scheme) {
      case 0: colour = RED; break; // Fixed colour
      case 1: colour = GREEN; break; // Fixed colour
      case 2: colour = BLUE; break; // Fixed colour
      case 3: colour = rainbow(map(i, -angle, angle, 0, 127)); break; // Full spectrum blue to red
      case 4: colour = rainbow(map(i, -angle, angle, 63, 127)); break; // 0x07e0  to red (high temperature etc)
      case 5: colour = rainbow(map(i, -angle, angle, 127, 63)); break; // Red to 0x07e0  (low battery etc)
      default: colour = BLUE; break; // Fixed colour
    }

    // Calculate pair of coordinates for segment start
    float sx = cos((i - 90) * 0.0174532925);
    float sy = sin((i - 90) * 0.0174532925);
    uint16_t x0 = sx * (r - w) + x;
    uint16_t y0 = sy * (r - w) + y;
    uint16_t x1 = sx * r + x;
    uint16_t y1 = sy * r + y;

    // Calculate pair of coordinates for segment end
    float sx2 = cos((i + seg - 90) * 0.0174532925);
    float sy2 = sin((i + seg - 90) * 0.0174532925);
    int x2 = sx2 * (r - w) + x;
    int y2 = sy2 * (r - w) + y;
    int x3 = sx2 * r + x;
    int y3 = sy2 * r + y;

    if (i < v) { // Fill in coloured segments with 2 triangles
      tft.setColor(colour);
      geo.fillTriangle(x0, y0, x1, y1, x2, y2);
      geo.fillTriangle(x1, y1, x2, y2, x3, y3);
      text_colour = colour; // Save the last colour drawn
    }
    else // Fill in blank segments
    {
      tft.setColor(DARKGREY);
      geo.fillTriangle(x0, y0, x1, y1, x2, y2);
      geo.fillTriangle(x1, y1, x2, y2, x3, y3);
    }
  }
}


// #########################################################################
// Return a 16 bit rainbow colour
// #########################################################################
unsigned int rainbow(byte value)
{
  // Value is expected to be in range 0-127
  // The value is converted to a spectrum colour from 0 = blue through to 127 = red
  byte red = 0; // Red is the top 5 bits of a 16 bit colour value
  byte green  = 0;// 0x07e0  is the middle 6 bits
  byte blue = 0; // Blue is the bottom 5 bits
  byte quadrant = value / 32;
  if (quadrant == 0) {
    blue = 31;
    green  = 2 * (value % 32);
    red = 0;
  }
  if (quadrant == 1) {
    blue = 31 - (value % 32);
    green  = 63;
    red = 0;
  }
  if (quadrant == 2) {
    blue = 0;
    green  = 63;
    red = value % 32;
  }
  if (quadrant == 3) {
    blue = 0;
    green  = 63 - 2 * (value % 32);
    red = 31;
  }
  return (red << 11) + (green  << 5) + blue;
}




//#######################################################
//Nivelierung
//#######################################################
void getLevel()
{
  xyzFloat corrAngles = myAcc.getCorrAngles();
  tft.setColor(0x07e0);
  tft.fillCircle(400, 185, 50);
  tft.setColor(0x0000);
  tft.drawCircle(400, 185, 10);
  tft.setColor(0xFFFF);
  tft.drawCircle(400, 185, 51);
  tft.setFont(arial_round);


  //Variablen für Berechnungen definieren
  int Achsabstand = 410;
  int Radstand = 165;

  //Links Keile
  if (corrAngles.x > abwlr and corrAngles.y<abwhv and corrAngles.y> abwhv * -1)
  {
    if (corrAngles.x > 10 and corrAngles.y<abwhv and corrAngles.y> abwhv * -1)
    {
      corrAngles.x = 10;
    }
    tft.setColor(RED);
    tft.fillCircle(400 + corrAngles.y * 4, 185 + corrAngles.x * 4, 5);
    tft.print("Links ", 70, 320);
    links = (sin(corrAngles.x * rad)) * Radstand;
    ////Serial.println(corrAngles.x);
    ////Serial.println(links);
    tft.printNumF(links, 1, 70, 350);
    tft.print(" cm             ", 110, 350);
    tft.setColor(RED);
    tft.fillRect(301, 101, 359, 119);
    tft.setColor(GREEN);
    tft.fillRect(301, 251, 359, 269);
    tft.setColor(RED);
    tft.fillRect(11, 101, 69, 119);
    tft.setColor(GREEN);
    tft.fillRect(11, 251, 69, 269);
  }

  //Rechts Keile
  if (corrAngles.x < abwlr * -1 and corrAngles.y<abwhv and corrAngles.y> abwhv * -1)
  {
    if (corrAngles.x < -10 and corrAngles.y<abwhv and corrAngles.y> abwhv * -1)
    {
      corrAngles.x = -10;
    }
    tft.setColor(RED);
    tft.fillCircle(400 + corrAngles.y * 4, 185 + corrAngles.x * 4, 5);
    tft.print("Rechts ", 70, 320);
    rechts = (sin(corrAngles.x * -1 * rad)) * Radstand;
    ////Serial.println(corrAngles.x);
    ////Serial.println(rechts);
    tft.printNumF(rechts, 1, 70, 350);
    tft.print(" cm             ", 110, 350);
    tft.setColor(GREEN);
    tft.fillRect(301, 101, 359, 119);
    tft.setColor(RED);
    tft.fillRect(301, 251, 359, 269);
    tft.setColor(GREEN);
    tft.fillRect(11, 101, 69, 119);
    tft.setColor(RED);
    tft.fillRect(11, 251, 69, 269);
  }

  //Vorne Keile
  if (corrAngles.y < abwhv * -1 and corrAngles.x<abwlr and corrAngles.x> abwlr * -1)
  {
    if (corrAngles.y < - 10 and corrAngles.x<abwlr and corrAngles.x> abwlr * -1)
    {
      corrAngles.y = -10;
    }
    tft.setColor(RED);
    tft.fillCircle(400 + corrAngles.y * 4, 185 + corrAngles.x * 4, 5);
    tft.print("Vorne ", 70, 320);
    vorne = (sin(corrAngles.y * -1 * rad)) * Achsabstand;
    ////Serial.println(corrAngles.y);
    ////Serial.println(vorne);
    tft.printNumF(vorne, 1, 70, 350);
    tft.print(" cm             ", 110, 350);
    tft.setColor(RED);
    tft.fillRect(301, 101, 359, 119);
    tft.setColor(RED);
    tft.fillRect(301, 251, 359, 269);
    tft.setColor(GREEN);
    tft.fillRect(11, 101, 69, 119);
    tft.setColor(GREEN);
    tft.fillRect(11, 251, 69, 269);
  }

  //Hinten Keile
  if (corrAngles.y > abwhv and corrAngles.x<abwlr and corrAngles.x> abwlr * -1)
  {
    if (corrAngles.y > 10 and corrAngles.x<abwlr and corrAngles.x> abwlr * -1)
    {
      corrAngles.y = 10;
    }
    tft.setColor(RED);
    tft.fillCircle(400 + corrAngles.y * 4, 185 + corrAngles.x * 4, 5);
    tft.print("Hinten ", 70, 320);
    hinten = (sin(corrAngles.y * rad)) * Achsabstand;
    ////Serial.println(corrAngles.y);
    ////Serial.println(hinten, 1);
    tft.printNumF(hinten, 1, 70, 350);
    tft.print(" cm             ", 110, 350);
    tft.setColor(GREEN);
    tft.fillRect(301, 101, 359, 119);
    tft.setColor(GREEN);
    tft.fillRect(301, 251, 359, 269);
    tft.setColor(RED);
    tft.fillRect(11, 101, 69, 119);
    tft.setColor(RED);
    tft.fillRect(11, 251, 69, 269);
  }

  //Hinten Links Keile
  if (corrAngles.x > abwlr and corrAngles.y > abwhv)
  {
    tft.setColor(RED);
    tft.fillCircle(400 + corrAngles.y * 4, 185 + corrAngles.x * 4, 5);
    tft.print("Hinten Links ca. ", 70, 320);
    hinten = (sin(corrAngles.y * rad)) * Achsabstand;
    links = (sin(corrAngles.x * rad)) * Radstand;
    ////Serial.println(corrAngles.y);
    ////Serial.println(hinten, 1);
    if (hinten < links)tft.printNumF(links, 1, 70, 350);
    if (hinten > links)tft.printNumF(hinten, 1, 70, 350);
    tft.print(" cm  ", 110, 350);
    tft.setColor(GREEN);
    tft.fillRect(301, 101, 359, 119);
    tft.setColor(GREEN);
    tft.fillRect(301, 251, 359, 269);
    tft.setColor(RED);
    tft.fillRect(11, 101, 69, 119);
    tft.setColor(GREEN);
    tft.fillRect(11, 251, 69, 269);
  }

  //Hinten Rechts Keile
  if (corrAngles.x < abwlr * -1 and corrAngles.y > abwhv)
  {
    tft.setColor(RED);
    tft.fillCircle(400 + corrAngles.y * 4, 185 + corrAngles.x * 4, 5);
    tft.print("Hinten Rechts ca. ", 70, 320);
    hinten = (sin(corrAngles.y * rad)) * Achsabstand;
    rechts = (sin(corrAngles.x * -1 * rad)) * Radstand;
    ////Serial.println(corrAngles.y);
    ////Serial.println(hinten, 1);
    if (hinten < rechts)tft.printNumF(links, 1, 70, 350);
    if (hinten > rechts)tft.printNumF(hinten, 1, 70, 350);
    tft.print(" cm  ", 110, 350);
    tft.setColor(GREEN);
    tft.fillRect(301, 101, 359, 119);
    tft.setColor(GREEN);
    tft.fillRect(301, 251, 359, 269);
    tft.setColor(GREEN);
    tft.fillRect(11, 101, 69, 119);
    tft.setColor(RED);
    tft.fillRect(11, 251, 69, 269);
  }

  //Vorne Links Keile
  if (corrAngles.x > abwlr and corrAngles.y < abwhv * -1)
  {
    tft.setColor(RED);
    tft.fillCircle(400 + corrAngles.y * 4, 185 + corrAngles.x * 4, 5);
    tft.print("Vorne Links ca. ", 70, 320);
    vorne = (sin(corrAngles.y * -1 * rad)) * Achsabstand;
    links = (sin(corrAngles.x * rad)) * Radstand;
    ////Serial.println(corrAngles.y);
    ////Serial.println(hinten, 1);
    if (vorne < links)tft.printNumF(links, 1, 70, 350);
    if (vorne > links)tft.printNumF(vorne, 1, 70, 350);
    tft.print(" cm  ", 110, 350);
    tft.setColor(RED);
    tft.fillRect(301, 101, 359, 119);
    tft.setColor(GREEN);
    tft.fillRect(301, 251, 359, 269);
    tft.setColor(GREEN);
    tft.fillRect(11, 101, 69, 119);
    tft.setColor(GREEN);
    tft.fillRect(11, 251, 69, 269);
  }

  //Vorne Rechts Keile
  if (corrAngles.x < abwlr * -1 and corrAngles.y < abwhv * -1)
  {
    tft.setColor(RED);
    tft.fillCircle(400 + corrAngles.y * 4, 185 + corrAngles.x * 4, 5);
    tft.print("Vorne Rechts ca. ", 70, 320);
    vorne = (sin(corrAngles.y * -1 * rad)) * Achsabstand;
    rechts = (sin(corrAngles.x * -1 * rad)) * Radstand;
    ////Serial.println(corrAngles.y);
    ////Serial.println(hinten, 1);
    if (vorne < rechts)tft.printNumF(links, 1, 70, 350);
    if (vorne > rechts)tft.printNumF(hinten, 1, 70, 350);
    tft.print(" cm  ", 110, 350);
    tft.setColor(GREEN);
    tft.fillRect(301, 101, 359, 119);
    tft.setColor(RED);
    tft.fillRect(301, 251, 359, 269);
    tft.setColor(GREEN);
    tft.fillRect(11, 101, 69, 119);
    tft.setColor(GREEN);
    tft.fillRect(11, 251, 69, 269);
  }
  if ((corrAngles.x < abwlr and corrAngles.x > abwlr * -1) and (corrAngles.y  < abwhv and corrAngles.y  > abwhv * -1))
  {
    ////Serial.println("Juhuu");
    ////Serial.println(corrAngles.x);
    tft.setColor(RED);
    tft.fillCircle(400 + corrAngles.y * 4, 185 + corrAngles.x * 4, 5);
    tft.print("                                  ", 70, 350);
    tft.print("                                  ", 70, 320);
    tft.setColor(GREEN);
    tft.fillRect(11, 101, 69, 119);
    tft.fillRect(11, 251, 69, 269);
    tft.fillRect(301, 101, 359, 119);
    tft.fillRect(301, 251, 359, 269);
  }
}


void farben()
{
  cursx = 0;
  for (rot = 0; rot < 255; rot++)
  {
    Vorder = RGB565(rot, 0, 0);
    tft.fillRect(fx + cursx, fy, 1, 30);
    cursx++;
    ////Serial.println(fx + cursx);
    tft.drawRect(fx - 1, fy - 1, 256, 30);
  }
  cursx = 0;
  for (gruen = 0; gruen < 255; gruen++)
  {
    Vorder = RGB565(0, gruen, 0);
    tft.fillRect(fx + cursx, fy + 50, 1, 30);
    cursx++;
    tft.drawRect(fx - 1, fy + 50 - 1, 256, 30);
  }
  cursx = 0;
  for (blau = 0; blau < 255; blau++)
  {
    Vorder = RGB565(0, 0, blau);
    tft.fillRect(fx + cursx, fy + 100, 1, 30);
    cursx++;
    tft.drawRect(fx - 1, fy + 100 - 1, 256, 30);
  }
  selBlau = 0;
  selRot = 0;
  selGruen = 0;
  tx = 127;
  ty = fy + 5;
}




//##############################################
//#Farben von Touchscreen
//##############################################
void Farbenwahl()
{

}


void drawSlider(int x, int y, int slideLength,  int sliderWidth, int sliderHeight, int color, int bordercolor)
{
  tft.setColor(color);
  tft.drawRect(x - sliderWidth / 2 - 1, y - sliderHeight / 2 - 1, slideLength + sliderWidth / 2 + 1 + x, sliderHeight + 2 + y);
  tft.fillRect(x - sliderWidth / 2 + 1 / 2, y - sliderHeight / 2 + 1 / 2, sliderWidth - 2, sliderHeight - 2);
  tft.setColor(bordercolor);
  tft.drawRect(x - sliderWidth / 2, y - sliderHeight / 2, sliderWidth, sliderHeight);
}


void drawSwitch (int x, int y, int swLength, int swWidth, int color, int swStatus)
{
  if (swStatus == 0)
  {
    tft.setColor(Vorder);
    tft.drawRoundRect(x, y - swWidth / 2, swLength + x, swWidth / 2 + y);
    tft.fillRoundRect(x + 2, y - swWidth / 2 + 2, x + swLength / 5, swWidth / 2 + y - 2);
    tft.setColor(0x0000);
    tft.fillRoundRect(x + swLength - swLength / 5, y - swWidth / 2 + 2, x + swLength - 2, swWidth / 2 + y - 2);
  }
  if (swStatus == 1)
  {
    tft.setColor(Vorder);
    tft.drawRoundRect(x, y - swWidth / 2, swLength + x, swWidth / 2 + y);
    tft.fillRoundRect(x + swLength - swLength / 5, y - swWidth / 2 + 2, x + swLength - 2, swWidth / 2 + y - 2);
    tft.setColor(0x0000);
    tft.fillRoundRect(x + 2, y - swWidth / 2 + 2, x + swLength / 5, swWidth / 2 + y - 2);
  }
}




void Wechselrichter()
{
  if ((wechselrichterStatus = true))
    wechselrichterStatus = false;
  else if ((wechselrichterStatus = false))
    wechselrichterStatus = true;
}


void showSolar200()
{
  Serial.println("------ -200W------");
  Serial.print("Produkt ID : ");
  Serial.println(PID200);
  Serial.print("Firmware : ");
  Serial.println(FW200);
  Serial.print("Serien#: ");
  Serial.println(SER200);
  Serial.print("Betteriespannung : ");
  Serial.print(V200);
  Serial.println(" V");
  Serial.print("Batterie Ladestrom : ");
  Serial.print(Ib200);
  Serial.println(" A");
  Serial.print("Solarspannung : ");
  Serial.print(VPV200);
  Serial.println(" V");
  Serial.print("Solarleistung : ");
  Serial.print(PPV200);
  Serial.println(" W");
  Serial.print("Ladestatus : ");
  Serial.print(CS200);
  Serial.println(" -> 0 = Aus, 2 = Err, 3 = Lad, 4 = Entl, 5 = halten");
  Serial.print("MPPT : ");
  Serial.println(MPPT200);
  Serial.print("OR : ");
  Serial.println(OR200);
  Serial.print("Error : ");
  Serial.print(ERR200);
  Serial.println(" -> 0 = OK, 2 = Batt V zu hoch, 17 = Temp zu hoch, 18 = Überstrom, 21 = Amp Sensor Fehler, 33 = Solar V zu hoch, 34 = Solar A zu hoch");
  Serial.print("Lastausgang : ");
  Serial.println(LOAD200);
  Serial.print("Lastausgang Strom : ");
  Serial.print(IL200);
  Serial.println(" A");
  Serial.print("Ertrag gesamt : ");
  Serial.print(H19200);
  Serial.println(" kWh");
  Serial.print("Ertrag heute : ");
  Serial.print(H20200);
  Serial.println(" Wh");
  Serial.print("Maximalleistung heute : ");
  Serial.print(H21200);
  Serial.println(" W");
  Serial.print("Leistung gestern : ");
  Serial.print(H22200);
  Serial.println(" Wh");
  Serial.print("Maximalleistung gestern : ");
  Serial.print(H23200);
  Serial.println(" W");
  Serial.print("HSDS : ");
  Serial.println(HSDS200);
}

void showSolar160()
{
  Serial.println("------ -160W------");
  Serial.print("Produkt ID : ");
  Serial.println(PID160);
  Serial.print("Firmware : ");
  Serial.println(FW160);
  Serial.print("Serien#: ");
  Serial.println(SER160);
  Serial.print("Betteriespannung : ");
  Serial.print(V160);
  Serial.println(" V");
  Serial.print("Batterie Ladestrom : ");
  Serial.print(Ib160);
  Serial.println(" A");
  Serial.print("Solarspannung : ");
  Serial.print(VPV160);
  Serial.println(" V");
  Serial.print("Solarleistung : ");
  Serial.print(PPV160);
  Serial.println(" W");
  Serial.print("Ladestatus : ");
  Serial.print(CS160);
  Serial.println(" -> 0 = Aus, 2 = Err, 3 = Lad, 4 = Entl, 5 = halten");
  Serial.print("MPPT : ");
  Serial.println(MPPT160);
  Serial.print("OR : ");
  Serial.println(OR160);
  Serial.print("Error : ");
  Serial.print(ERR160);
  Serial.println(" -> 0 = OK, 2 = Batt V zu hoch, 17 = Temp zu hoch, 18 = Überstrom, 21 = Amp Sensor Fehler, 33 = Solar V zu hoch, 34 = Solar A zu hoch");
  Serial.print("Lastausgang : ");
  Serial.println(LOAD160);
  Serial.print("Lastausgang Strom : ");
  Serial.print(IL160);
  Serial.println(" A");
  Serial.print("Ertrag gesamt : ");
  Serial.print(H19160);
  Serial.println(" kWh");
  Serial.print("Ertrag heute : ");
  Serial.print(H20160);
  Serial.println(" Wh");
  Serial.print("Maximalleistung heute : ");
  Serial.print(H21160);
  Serial.println(" W");
  Serial.print("Leistung gestern : ");
  Serial.print(H22160);
  Serial.println(" Wh");
  Serial.print("Maximalleistung gestern : ");
  Serial.print(H23160);
  Serial.println(" W");
  Serial.print("HSDS : ");
  Serial.println(HSDS160);
}


void getSolar200()
{
  if (Serial1.available() > 10) {
    //Serial.println("Daten verfügbar");
    label200 = Serial1.readStringUntil('\t');
    val200 = Serial1.readStringUntil('\r\r\n');
    if (label200 == "PID") {
      PID200 = val200;
    } else if (label200 == "FW") {
      FW200 = val200;
    } else if (label200 == "SER#") {
      SER200 = val200;
    } else if (label200 == "V") {
      float temp = val200.toFloat();
      temp = temp / 1000;
      V200 = temp;
    } else if (label200 == "I") {
      Ib200 = val200.toFloat();
    } else if (label200 == "VPV") {
      float temp = val200.toFloat();
      temp = temp / 1000;
      VPV200 = temp;
    } else if (label200 == "PPV") {
      PPV200 = val200.toFloat();
    } else if (label200 == "CS") {
      CS200 = val200.toInt();
    } else if (label200 == "MPPT") {
      MPPT200 = val200;
    } else if (label200 == "OR") {
      OR200 = val200;
    } else if (label200 == "ERR") {
      ERR200 = val200.toInt();
    } else if (label200 == "LOAD") {
      LOAD200 = val200.toFloat();
    } else if (label200 == "IL") {
      IL200 = val200.toFloat();
    } else if (label200 == "H19") {
      int temp = val200.toInt();
      temp = temp * 10;
      H19200 = temp;
    } else if (label200 == "H20") {
      int temp = val200.toInt();
      temp = temp * 10;
      H20200 = temp;
    } else if (label200 == "H21") {
      H21200 = val200.toInt();
    } else if (label200 == "H22") {
      int temp = val200.toInt();
      temp = temp * 10;
      H22200 = temp;
    } else if (label200 == "H23") {
      H23200 = val200.toInt();
    } else if (label200 == "HSDS") {
      HSDS200 = val200.toInt();
    }
    //showSolar200();
  }
}


void getSolar160()
{
  if (Serial3.available() > 10) {
    //Serial.println("Daten verfügbar");
    label160 = Serial1.readStringUntil('\t');
    val160 = Serial1.readStringUntil('\r\r\n');
    if (label160 == "PID") {
      PID160 = val160;
    } else if (label160 == "FW") {
      FW160 = val160;
    } else if (label160 == "SER#") {
      SER160 = val160;
    } else if (label160 == "V") {
      float temp = val160.toFloat();
      temp = temp / 1000;
      V160 = temp;
    } else if (label160 == "I") {
      Ib160 = val160.toFloat();
    } else if (label160 == "VPV") {
      float temp = val160.toFloat();
      temp = temp / 1000;
      VPV160 = temp;
    } else if (label160 == "PPV") {
      PPV160 = val160.toFloat();
    } else if (label160 == "CS") {
      CS160 = val160.toInt();
    } else if (label160 == "MPPT") {
      MPPT160 = val160;
    } else if (label160 == "OR") {
      OR160 = val160;
    } else if (label160 == "ERR") {
      ERR160 = val160.toInt();
    } else if (label160 == "LOAD") {
      LOAD160 = val160.toFloat();
    } else if (label160 == "IL") {
      IL160 = val160.toFloat();
    } else if (label160 == "H19") {
      int temp = val160.toInt();
      temp = temp * 10;
      H19160 = temp;
    } else if (label160 == "H20") {
      int temp = val160.toInt();
      temp = temp * 10;
      H20160 = temp;
    } else if (label160 == "H21") {
      H21160 = val160.toInt();
    } else if (label160 == "H22") {
      int temp = val160.toInt();
      temp = temp * 10;
      H22160 = temp;
    } else if (label160 == "H23") {
      H23160 = val160.toInt();
    } else if (label160 == "HSDS") {
      HSDS160 = val160.toInt();
    }
  }
}


void updateSolarWerte()
{
  for (int r = 0; r < 200; r++)
  {
    getSolar200();
    getSolar160();
  }
  tft.setColor(Schriftf);
  tft.setBackColor(0x0000);
  tft.setFont(arial_round);

  tft.printNumF((V200 + V160) / 2, 2, 280, 50);
  tft.printNumF(Ib200 + Ib160, 2, 280, 70);
  tft.printNumF(H19200 + H19160, 2, 280, 90);
  tft.printNumF(H20200 + H20160, 2, 280, 110);
  tft.printNumF(H21200 + H21160, 2, 280, 130);
  tft.printNumF(H22200 + H22160, 2, 280, 150);
  tft.printNumF(H23200 + H23160, 2, 280, 170);
  //showSolar200();
  //showSolar160();
  hbp();
  label200 = "0";
  label160 = "0";
}


void updateSolarScreen()
{
  for (int r = 0; r < 200; r++)
  {
    getSolar200();
    getSolar160();
  }
  tft.setColor(Schriftf);
  tft.setBackColor(0x0000);
  tft.setFont(arial_round);
  tft.printNumF((VPV200 + VPV160) / 2, 2, 50, 167 - 14);
  tft.print(" V", 110, 167 - 14);
  ringMeter((VPV200 + VPV160) / 2, 12, 45, 120 - radius - 30, 160 - radius, radius, RED2GREEN  );
  //Amps
  tft.printNumF((PPV200 + PPV160) / ((VPV200 + VPV160) / 2), 2, 200, 167 - 14);
  ////Serial.print(" A");
  ////Serial.println(PPV / VPV);
  tft.print(" A", 260, 167 - 14);
  ringMeter((PPV200 + PPV160) / (VPV200 + VPV160) / 2, 0, 20, 240 - radius, 160 - radius, radius, RED2GREEN  );
  //Watts
  tft.printNumF((PPV200 + PPV160), 0, 361, 167 - 14);
  tft.print(" W", 398, 167 - 14);
  ringMeter(PPV200 + PPV160, 1, 360, 360 - radius + 30, 160 - radius, radius, RED2GREEN  );
  label200 = "0";
  label160 = "0";

}


void updateBatterie()
{
  getSolar200();
  int radius = 70;
  tft.setColor(Schriftf);
  tft.setBackColor(0x0000);
  tft.setFont(arial_round);
  tft.print("Aufbaubatterie", 48, 70);


  tft.printNumF(V200, 2, 80, 153);
  tft.print(" V", 140, 153);
  ringMeter(V200, 11.6, 14.4, 120 - radius, 160 - radius, radius, RED2GREEN  );
  //Bordbatterie
  tft.setColor(Schriftf);
  tft.setBackColor(0x0000);
  tft.setFont(arial_round);

  tft.print("Bordbatterie", 298, 70);

  tft.printNumF(Bordbatterie / 100, 2, 320, 153);
  tft.print(" V", 380, 153);
  ringMeter(Bordbatterie, 1100, 1500, 360 - radius, 160 - radius, radius, RED2GREEN  );

  label200 = "0";
}


void getBaroTrend()
{
  //Serial.println("Reading Barometer");
  // Serial.println(b);
  BME280::TempUnit tempUnit(BME280::TempUnit_Celsius);
  BME280::PresUnit presUnit(BME280::PresUnit_Pa);
  if (b == 99)
  {

    bme.read(pres, temp, hum, tempUnit, presUnit);
    baro[b] = pres + 9840;
    b--;
  }
  if ((b > 0) and (b < 99))
  {

    baro[b] = baro[b + 1];
    bme.read(pres, temp, hum, tempUnit, presUnit);
    baro[b + 1] = pres + 9840;
    /*    Serial.print("Counter: ");Serial.println(b+1);
        Serial.print("Counter-1: ");Serial.println(b);
        Serial.print("b: "); Serial.println(baro[b + 1]);
        Serial.print("b-1: "); Serial.println(baro[b]);
    */
    b--;
  }
  else
  {

    for (int Fifo = 0; Fifo < 99; Fifo++)
    {
      baro[Fifo] = baro[Fifo + 1];
      Serial.print("FiFo: "); Serial.println(baro[Fifo]);
    }
    bme.read(pres, temp, hum, tempUnit, presUnit);
    baro[99] = pres + 9840;


  }
}


void getTouched()
{
  tx = 0;
  ty = 0;
  // See if there's any  touch data for us
  if (ts.touched())
  {
    // Retrieve a point
    TS_Point p = ts.getPoint();
    down = 1;
    ty = p.y - offsetY;
    tx = p.x;
    // Serial.print("Downstatus: ");
    // Serial.println(down);

  }

}


void Button(int x, int y, int btnX, int btnY, int colorF, int colorS, String btnText, uint8_t *Schrift)
{
  Serial.print("PosX : ");
  Serial.println(x);
  Serial.print("SizeX : ");
  Serial.println(btnX);
  Serial.print("PosY : ");
  Serial.println(y);
  Serial.print("SizeY : ");
  Serial.println(btnY );
  Serial.println(btnText);
  tft.setColor(colorF);
  tft.fillRoundRect(x - btnX / 2, y - btnY / 2, x + btnX / 2, y + btnY / 2);
  tft.setColor(WHITE);
  tft.drawRoundRect(x - btnX / 2, y - btnY / 2, x + btnX / 2, y + btnY / 2);
  tft.setColor(colorS);
  tft.setBackColor(colorF);
  tft.setFont(Schrift);
  int textlength, textheight, laenge;
  laenge = btnText.length();
  textlength = tft.getFontXsize() * laenge;
  textheight = tft.getFontYsize();
  tft.print(btnText, x - textlength / 2, y - textheight / 2 + 2);
  tft.setBackColor(0x0000);
  tx = 0;
  ty = 0;
}

Edit: Dies ist der Sketch mit der FT6206....also für diesen Thread nicht relevant

Habe eine Frage, wie Viele Pins werden benötigt, ist das 8 oder 16Bit Display?
Wen 8 Bit dann probiere mal die TFT_eSPI die kann auch dein Display (SSD1963_800) bei der UTFT dauert zeichnen Ewigkeit bei 800 Pixel. Bei mir mit 8Bit Display Änderung der Hintergrundfarbe bei 480x320 dauert unter 0,5 Sek. mit einem ESP32, bei SPI Displays noch schneller.