3.2 Zoll TFT mit Touch MY32D

Ich habe ein 3.2 Zoll Farb TFT vom Chinamann welches ich mit einen Arduino Mega 2560 Board ansteuere.

Zuhilfe nehme ich mit die Libarys UTOUCH und UTFT.

Aktuell erstelle ich ein Programm welches auf dem 3.2'' TFT

  • Die Aktuelle Zeit
  • Das Aktuelle Datum
  • Resttage
  • Rrestzeit

anzeigt.

Funktionen sind:

  • Aktuelle zeit ändern (Schreiben per I2C Bus zum DS11307)
  • Ende verändern (Speichern im EEPROM)
  • Farben ändern (Speichern im EEPROM)

 

Beispielprogramm

#include <memorysaver.h>
#include <UTFT.h>
#include <UTouch.h>
#include "Wire.h"
#include <SoftwareSerial.h>
#include <EEPROM.h>
#include <Ethernet.h>
#include <SPI.h>
#define DS1307_I2C_ADDRESS 0x68                          // I2C Adresse

byte mac[] = {                                           //Netzwerk
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; 
IPAddress ip(192,168,178,177);
EthernetServer server(80);

extern uint8_t BigFont[];

// Uncomment the next two lines for the Arduino Mega
UTFT        myGLCD(ITDB32S, 38,39,40,41);   // Remember to change the model parameter to suit your display module!
UTouch      myTouch(6,5,4,3,2);

int page, runden;
char buffer[20] = "";                                    // Speicherbereich für Datenkonvertierung 
byte second, second3, minute, hour, dayOfWeek, dayOfMonth, month, year, second2, minute2, hour2, dayOfMonth2, month2, monat, year2,tagemonat, resttage,restmonate, reststunden,restminuten,restsecunden; 
byte BGR, BGG, BGB, CR, CG ,CB;
int led =13;
int command = 0;  
char  *Day[] = {"","Sontag","Montag","Dienstag","Mittwoch","Donnerstag","Freitag","Samstag"};
char  *Mon[] = {"","Januar","Febuar","Maerz","April","May","Juni","Juli","August","September","Oktober","November","Dezember"};


byte decToBcd(byte val)// Convert normal decimal numbers to binary coded decimal
{
  return ( (val/10*16) + (val%10) );
}
byte bcdToDec(byte val)// Convert binary coded decimal to normal decimal numbers
{
  return ( (val/16*10) + (val%16) );
}
void DatumSchreiben(int x, int y, byte t, byte m, byte j)
{
	//Zeit an die Koordinaten x y schreiben
	//Programm Speicher einsparungen =1416 2,3% voher 60390 bytes nacher 58974
			  //x H
	int x1=x+16;//H
	int x2=x+32;//:
	int x3=x+48;//M
	int x4=x+64;//M
	int x5=x+80;//:
	int x6=x+96;//S
	int x7=x+112;//S
	
	if (dayOfMonth<10)
    {
       myGLCD.print("0",x,y);
      myGLCD.printNumI(dayOfMonth,x1,y);
     }
     
  if (dayOfMonth>=10)
    myGLCD.printNumI(dayOfMonth,x,y);
	
	myGLCD.print(".",x2,y); 
 
 if ( month<10)
   {
     myGLCD.print("0",x3,y);
     myGLCD.printNumI(month,x4,y);
   }
  if (month>=10)
    myGLCD.printNumI(month,x3,y);
    
  myGLCD.print(".",x5,y);
  if (j>=10)
  myGLCD.printNumI(j,x6,y);
  else
  {
	  myGLCD.print("0",x6,y);
	  myGLCD.printNumI(j,x7,y);
  }	
 	
}
void ZeitSchreiben(int x, int y, byte st, byte mi, byte se)
{
	//Zeit an die Koordinaten x y schreiben
	//Programm Speicher einsparungen =1416 voher 60390 bytes 59452Zeit 58974 
	//58418 nach änderungen -> 1972 eingespart
			  //x H
	int x1=x+16;//H
	int x2=x+32;//:
	int x3=x+48;//M
	int x4=x+64;//M
	int x5=x+80;//:
	int x6=x+96;//S
	int x7=x+112;//S
	
	if (st<10)
  {
	myGLCD.print(" ",x,y);
    myGLCD.printNumI(st,x1,y);
  }
  if (st>=10)
    myGLCD.printNumI(st,x,y);
    
  myGLCD.print(":",x2,y);
  
  if (mi<10)
    {
        myGLCD.print("0",x3,y); 
        myGLCD.printNumI(mi,x4,y); 
    }
    
  if (mi>=10)
    myGLCD.printNumI(mi,x3,y); 
    
  myGLCD.print(":",x5,y);
  
  if (se<10)
    {
      myGLCD.print("0",x6,y); 
      myGLCD.printNumI(se,x7,y); 
    }
    
  if (se>=10)
    myGLCD.printNumI(se,x6,y);   
	
	
	
}
void msg(char* meldung)
{
			myGLCD.setColor(VGA_LIME);
			myGLCD.fillRect(45,75,275,165);
			myGLCD.setColor(255,0,0);
			myGLCD.setBackColor(VGA_LIME);
			myGLCD.fillRect(50,80,270,160);
			myGLCD.print(meldung,CENTER,115);
			delay(1000);
			myGLCD.setColor(CR, CG, CB);
			myGLCD.setBackColor(BGR, BGG, BGB);
}		
void getDOM(byte month)  //Tage eines Monats auslesen
{
  tagemonat=0;
 if (month==1)
   tagemonat=31;
 if (month==2)
   tagemonat=30;
  if (month==3)
   tagemonat=31;
  if (month==4)
   tagemonat=30;
  if (month==5)
   tagemonat=31;
  if (month==6)
   tagemonat=30;
  if (month==7)
   tagemonat=31;
  if (month==8)
   tagemonat=31;
  if (month==9)
   tagemonat=30;
  if (month==10)
   tagemonat=31;
  if (month==11)
   tagemonat=30;
  if (month==12)
   tagemonat=31;
}
void getDateDs1307()
{

  
  Wire.beginTransmission(DS1307_I2C_ADDRESS);         // I2C-Kommunikation im Schreibmodus starten
  Wire.write(0x00);                                    // Registerzeiger auf 0 setzen
  Wire.endTransmission();                             // I2C-Kommunikation beenden 
  Wire.requestFrom(DS1307_I2C_ADDRESS, 7);            // I2C-Kommunikation im Lesemodus starten
 
  second     = bcdToDec(Wire.read() & 0x7f);
  minute     = bcdToDec(Wire.read());
  hour       = bcdToDec(Wire.read());  // Need to change this if 12 hour am/pm& 0x3f
  dayOfWeek  = bcdToDec(Wire.read());
  dayOfMonth = bcdToDec(Wire.read());
  month      = bcdToDec(Wire.read());
  year       = bcdToDec(Wire.read());
 
 monat=month;
}
void writeDateTime()
  {

  /*************************TFT Datum und Zeit schreiben***/ 
  DatumSchreiben(98, 85, dayOfMonth, month, year);
  ZeitSchreiben(100, 35, hour, minute, second);
   
/**********************  Zeit berechnen*******************/   
    
  if (month<month2)
    {
     getDOM(month); 
      resttage=tagemonat-dayOfMonth;
      resttage=resttage+dayOfMonth2;
    };
restmonate= month2-month;

while(restmonate>1)
      {
        month=month+1;
        getDOM(month);
        resttage=resttage+tagemonat;
        restmonate= month2-month;
      }
  if (second>second2)
    {
      second2=second2+60;
      if (minute2==0)
      {
        minute2 = minute2+60;
          
           if (hour2 == 0)
           {
            hour2=hour2+24;
            resttage=resttage-1;
           }
           
        hour2=hour2-1;
      }
      
      minute2=minute2-0x01;
      //Serial.println("Secunde +60 Minute -1");
    }
    
   if (minute>minute2)
   {
     //Serial.println(" minure +60 Stunde -1");
     minute2=minute2+60;
     hour2=hour2-0x01;
   }
  if(hour>=hour2)
    {
      //Serial.println("Stunde +24 TAge -1");
      hour2=hour2+24;
      resttage=resttage-1;
    }
  reststunden = hour2 - hour;
  restminuten = minute2 - minute; 
  restsecunden = second2 -second;
 
   //TFT Rest Zeit schreiben 
	ZeitSchreiben(100, 185, reststunden, restminuten, restsecunden);
	
	//TFT Rest Tage schreiben
	myGLCD.printNumI(resttage,CENTER,135); 

 /* 
  Serial.print("Noch ");
  Serial.print(resttage, DEC);
  Serial.print(" Tage ");
  Serial.print(reststunden);
  Serial.print(" Stunden ");
  Serial.print(restminuten,DEC);
  Serial.print(" minuten und ");
  Serial.print(restsecunden);
  Serial.print(" Secunden!");  
  Serial.println();
  
  */
}
void menue()
{
  page=2;
  myGLCD.clrScr();
  myGLCD.fillScr(BGR,BGG,BGB);
  //myGLCD.setColor(CR, CG, CB);
  //myGLCD.setBackColor(BGR, BGG, BGB);
  myGLCD.print("http://ufoserver.de", CENTER, 220);
  myGLCD.print("Menue", CENTER, 5);
  myGLCD.print("EXIT", LEFT, 180);
  myGLCD.print("Uhr Stellen", LEFT, 40);
  myGLCD.print("Ende Stellen", LEFT, 130);
  myGLCD.print("Farbe einstellen", LEFT,85);
}  
void zeitstellen()
{
page=3;
  myGLCD.clrScr();
  myGLCD.fillScr(BGR,BGG,BGB);
  //myGLCD.setColor(CR, CG, CB);
  //myGLCD.setBackColor(BGR, BGG, BGB);
  myGLCD.print("http://ufoserver.de", CENTER, 220);
  myGLCD.print("Zeit/Datum Stellen", CENTER, 10);
  
  myGLCD.print("EXIT", LEFT, 180);
  myGLCD.print("SAVE", RIGHT, 180);
  plusminus();
  getDateDs1307();
  zeitdatumschreibenTIME();
	
}
void endestellen()
{
page=4;
  myGLCD.clrScr();
  myGLCD.fillScr(BGR,BGG,BGB);
  //myGLCD.setColor(CR, CG, CB);
  //myGLCD.setBackColor(BGR, BGG, BGB);
  myGLCD.print("http://ufoserver.de", CENTER, 220);
  myGLCD.print("Ende Stellen", CENTER, 10);
  myGLCD.print("EXIT", LEFT, 180);
  myGLCD.print("SAVE", RIGHT, 180);
  
  second2 = EEPROM.read(1);
  minute2 = EEPROM.read(2);
  hour2 = EEPROM.read(3);
  dayOfMonth2 = EEPROM.read(4);
  month2 = EEPROM.read(5);
  year2 = EEPROM.read(6);
  
  zeitdatumschreibenENDE();
  plusminus();
	
}
void farbe()//Menü zur auswahl der Farbe
{
	page=5;
  myGLCD.clrScr();
  myGLCD.fillScr(BGR,BGG,BGB);
  myGLCD.setColor(CR, CG, CB); //Nicht löschen setzt global die neuen Farben!!
  myGLCD.setBackColor(BGR, BGG, BGB);//Nicht löschen setzt global die neuen Farben!!
  myGLCD.print("http://ufoserver.de", CENTER, 220);
  myGLCD.print("Farbe", CENTER, 10);
  myGLCD.print("EXIT", LEFT, 180);
  myGLCD.print("SAVE", RIGHT, 180);
  myGLCD.print("R  G  B   R  G  B", CENTER, 30);
  myGLCD.print(" Back ", LEFT, 150);
  myGLCD.print("Schrift", RIGHT, 150);
  BGR = EEPROM.read(7);
  BGG = EEPROM.read(8);
  BGB = EEPROM.read(9);
  CR = EEPROM.read(10);
  CG = EEPROM.read(11);
  CB = EEPROM.read(12);
  plusminus();
  farbenDaten();
  	
}
void zeitdatumschreibenENDE()//Schreibt das Datum und die Zeit an die gewünschte stelle
{
	 DatumSchreiben(16, 90, dayOfMonth2, month2, year2);
	 ZeitSchreiben(176, 90, hour2, minute2, second2);
}	
void zeitdatumschreibenTIME()//Schreibt das Datum und die Zeit an die gewünschte stelle
{
	DatumSchreiben(16, 90, dayOfMonth, month, year);
	ZeitSchreiben(176, 90, hour, minute, second);
}
void plus(int x, int y)//Generiert ein runden Button mit einen +
{
	int x2=x+31;
	int x3=x+14;
	int x4=x+18;
	int y2=y+31;
	int y3=y+15;
	int y4=y+18;
	int x5=x+16;
	int y5=y+16;
	myGLCD.setColor(VGA_NAVY);
	myGLCD.fillCircle(x5,y5,15);
	myGLCD.setColor(VGA_LIME);
	myGLCD.drawCircle(x5,y5,15);
	myGLCD.drawCircle(x5,y5,16);
	myGLCD.drawCircle(x5,y5,17);
	//myGLCD.drawRoundRect(x,y,x2,y2);
	myGLCD.fillRect(x,y3,x2,y4);
	myGLCD.fillRect(x3,y,x4,y2);
	myGLCD.setColor(CR, CG, CB);
}	
void minus(int x, int y)//Generiert ein runden Button mit einen -
{
	int x2=x+31;
	int x3=x+14;
	int x4=x+18;
	int y2=y+31;
	int y3=y+14;
	int y4=y+18;
	int x5=x+16;
	int y5=y+16;
	myGLCD.setColor(VGA_NAVY);
	myGLCD.fillCircle(x5,y5,15);
	myGLCD.setColor(VGA_LIME);
	myGLCD.drawCircle(x5,y5,15);
	myGLCD.drawCircle(x5,y5,16);
	myGLCD.drawCircle(x5,y5,17);
	//myGLCD.drawRoundRect(x,y,x2,y2);
	myGLCD.fillRect(x,y3,x2,y4);
	//myGLCD.fillRect(x3,y,x4,y2);
	myGLCD.setColor(CR, CG, CB);
	
}
void plusminus() //Plaziert Buttons für die menüs
{
	plus(16,54);
	plus(64,54);
	plus(112,54);
	plus(176,54);
	plus(224,54);
	plus(272,54);
	minus(16,110);
	minus(64,110);
	minus(112,110);
	minus(176,110);
	minus(224,110);
	minus(272,110);
	
}	
void neumalen() //Hautfenster neu generieren
{
	page=1;
  myGLCD.clrScr();
  myGLCD.fillScr(BGR,BGG,BGB);
  myGLCD.setColor(CR, CG, CB);
  myGLCD.setBackColor(BGR, BGG, BGB);
  myGLCD.print("http://ufoserver.de", CENTER, 220);
  myGLCD.print("Zeit", CENTER, 10);
  myGLCD.print("Datum", CENTER, 60);
  myGLCD.print("Resttage", CENTER, 110);
  myGLCD.print("Restzeit", CENTER, 160);
  myGLCD.drawRoundRect(265,170,305,210);
  myGLCD.drawRoundRect(264,171,304,209);
  myGLCD.drawPixel(285,190); 
   
	for(int z = 2; z < 19; z = z +2){
		myGLCD.drawCircle(285,190,z);
	} 

  
}
void byteSchreiben(int x, int y, byte farbe)//58974 58418
{
	int x2 = x + 16;
	int x3 = x + 32;
	if (farbe<10)
	{
		myGLCD.print("00",x,y);
		myGLCD.printNumI(farbe,x3,y);
	}
	else if (farbe<100)
	{
		myGLCD.print("0",x,y);
		myGLCD.printNumI(farbe,x2,y);
	}
	else
	myGLCD.printNumI(farbe,x,y);
	
}
void farbenDaten()
{
	myGLCD.setColor(CR, CG, CB);
    myGLCD.setBackColor(BGR, BGG, BGB);
	byteSchreiben(15, 90, BGR);
	byteSchreiben(64, 90, BGG);
	byteSchreiben(113, 90, BGB);
	byteSchreiben(174, 90, CR);
	byteSchreiben(223, 90, CG);
	byteSchreiben(272, 90, CB);
	myGLCD.print("TEST TEST", 90,180);
	
}	
void setup()
{
  Wire.begin();
  // start serial port at 9600 bps:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
  page=1;
  pinMode(led, OUTPUT);
    // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
  
  //EEPROM AUSLESEN BEIM START
  second2 = EEPROM.read(1);
  minute2 = EEPROM.read(2);
  hour2 = EEPROM.read(3);
  dayOfMonth2 = EEPROM.read(4);
  month2 = EEPROM.read(5);
  year2 = EEPROM.read(6);
  BGR = EEPROM.read(7);
  BGG = EEPROM.read(8);
  BGB = EEPROM.read(9);
  CR = EEPROM.read(10);
  CG = EEPROM.read(11);
  CB = EEPROM.read(12);


							//Startbildschirm erstellen
  myGLCD.InitLCD();
  myGLCD.clrScr();
  myGLCD.setFont(BigFont);
  myGLCD.setColor(CR, CG, CB);
  myGLCD.setBackColor(BGR, BGG, BGB);
  myTouch.InitTouch();
  myTouch.setPrecision(PREC_MEDIUM);

  myGLCD.print("3.2 TFT Touch", CENTER, 1);
  myGLCD.print("Mit der UTFT Lib und", CENTER, 50);
  myGLCD.print("der UTouch lib von", CENTER, 100);
  myGLCD.print("henningkarlsen.com", CENTER, 150);
  myGLCD.print("Let s go!!", CENTER, 200);
  delay(2000);
  
  myGLCD.setColor(VGA_LIME);
  myGLCD.setBackColor(VGA_RED);
  
  myGLCD.print("HALLO DU DA!", 15,220,350);
  myGLCD.print("HALLO DU DA!", 10,200,350);
  myGLCD.print("HALLO DU DA!", 5,180,350);
  delay(2000);
  
  neumalen();
}
void loop()
{
  if (page == 1)
  {
	  runden=runden+1;
	  if (runden == 250)
	  {
		  getDateDs1307();
		  if(second != second3)
		  {
			  writeDateTime();
			  second3=second;
		  }		
		  runden=0;
	  }
	}	
  
   
  EthernetClient client = server.available();
	if (client)
	{
	Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");  // the connection will be closed after completion of the response
	  client.println("Refresh: 5");  // refresh the page automatically every 5 sec
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
          client.println("<h1>");
          client.print("Zeit: ");
          client.print(hour);
          client.print(":");
          if (minute < 10)
          client.print("0");
          client.print(minute);
          client.print(":");
          if (second < 10)
          client.print("0");
          client.println(second);
          client.println("</h1>");
          client.println("<br />");
          client.println("<h1>");
          client.print("Datum: ");
          client.print(dayOfMonth);
          client.print(" ");
          client.print(Mon[monat]);
          client.print(" 20");
          if (year < 10)
          client.print("0");
          client.println(year);
          client.println("</h1>");
          client.println("<br />");
          client.println("<h1>");
          client.print("Resttage: ");
          client.print(resttage);
          client.println("</h1>");
          client.println("<br />");
          client.println("<h1>");
          client.print("Restzeit: ");
          client.print(reststunden);
          client.print(":");
          if (restminuten < 10)
          client.print("0");
          client.print(restminuten);
          client.print(":");
          if (restsecunden < 10)
          client.print("0");
          client.println(restsecunden);
          client.println("</h1>");
          client.println("<br />");
          client.println("</html>");
          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        } 
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
    // close the connection:
    client.stop();
    Serial.println("client disonnected");
	}	
  
  long x, y;
  
  while (myTouch.dataAvailable() == true)
  {
        myTouch.read();
    x = myTouch.getX();
    y = myTouch.getY();
    
	
	do
	{
		//Warten auf touch endabel
	} while (myTouch.dataAvailable() == false);
	
	Serial.print("X: ");
	Serial.println(x);
	Serial.print("Y: ");
	Serial.println(y);	
	if(page == 1)
	{
		if ((x<310 && x>270) && (y>170 && y<210))	//Menü aufrufen
		{
			menue();
			Serial.println("Menue");
			delay(50);
		}	
	}
	
	else if(page == 2)		//Page 2 ist die menü seite
	{
		if ((x<70 && x>0) && (y>160 && y<230))	//EXIT MENUE
		{
			neumalen();
			Serial.println("EXIT");
			delay(50);
		}
		if ((x<200 && x>0) && (y>30 && y<70))		//Uhr Stellen
		{
			Serial.println("Uhr Stellen");
			zeitstellen();
			delay(50);
		}
		if ((x<200 && x>0) && (y>120 && y<155))		//Ende Stellen
		{
			Serial.println("Ende Stellen");
			endestellen();
			delay(50);
		}
		if ((x<260 && x>0) && (y>75 && y<115))		//Farbe
		{
			Serial.println("Farbe Stellen");
			farbe();
			delay(50);
		}
			
	}
	else if(page == 3)		//Page 2 ist die Uhr Stellen seite
	{
		if ((x<70 && x>0) && (y>160 && y<230))	//EXIT MENUE
		{
			menue();
			Serial.println("EXIT");
			delay(50);
		}
		if ((x<300 && x>250) && (y>160 && y<230))		//Uhr Stellen
		{
			Serial.println("SAVE Data to clock");
			msg("TIME SAVE...");
			Wire.beginTransmission(DS1307_I2C_ADDRESS);         // I2C-Kommunikation im Schreibmodus starten
			Wire.write(0x00);
			Wire.write(decToBcd(second));                                    // Registerzeiger auf 0 setzen
			Wire.write(decToBcd(minute));
			Wire.write(decToBcd(hour));
			Wire.write(decToBcd(dayOfWeek));
			Wire.write(decToBcd(dayOfMonth));
			Wire.write(decToBcd(month));
			Wire.write(decToBcd(year)); 
			Wire.endTransmission();
			Serial.println("Daten gesendet!!");
			msg("DONE");
			zeitstellen();
			delay(50);
		}
																		//Buttons um die Zeit und das Datum zu ändern
		if ((x<47 && x>16) && (y>54 && y<85))		//Tag +
		{
			Serial.println("Tag+");
			getDOM(month);
			if (dayOfMonth >= tagemonat)
			{
				dayOfMonth=1;
				if (month >=12)
				{
					month=1;
					year++;
				}
				else
				{
					month=month+1;
				}								
			}
			else
			{
				dayOfMonth=dayOfMonth+1;
			}						
			zeitdatumschreibenTIME();
			delay(50);
		}		
		if ((x<95 && x>64) && (y>54 && y<85))		//Monat +
		{
			Serial.println("Monat+");
			if (month >=12)
				{
					month=1;
					year++;
				}
				else
				{
					month=month+1;
				}				
			zeitdatumschreibenTIME();
			delay(50);
		}
		if ((x<143 && x>112) && (y>54 && y<85))		//Jahr +
		{
			Serial.println("Jahr+");
			if (year >=99)
			{
				year=0;
			}
			else			
			year++;
			zeitdatumschreibenTIME();
			delay(50);
		}	
		if ((x<207 && x>176) && (y>54 && y<85))		//Stunde +
		{
			Serial.println("Stunde+");
			if (hour>=23)
			{
				hour=0;
				getDOM(month);
				if (dayOfMonth >= tagemonat)
				{
					dayOfMonth=1;
					if (month >=12)
					{
						month=1;
						year++;
					}
					else
					{
						month=month+1;
					}								
				}
				else
				{
					dayOfMonth=dayOfMonth+1;
				}				
				
			}
			else
			hour++;			
			zeitdatumschreibenTIME();
			delay(50);
		}	
		
		if ((x<255 && x>224) && (y>54 && y<85))		//Minute +
		{
			Serial.println("Minute+");
			
			if (minute>=59)
			{
				if (hour>=23)
				{
					minute=0;
					hour=0;
					getDOM(month);
					if (dayOfMonth >= tagemonat)
					{
						dayOfMonth=1;
						if (month >=12)
						{
							month=1;
							year++;
						}
						else
						{
							month=month+1;
						}								
					}
					else
					{
						dayOfMonth=dayOfMonth+1;
					}				
				
				}
				else
				{
					hour++;
					minute=0;
				}					
				
			}				
			else
			minute++;
			
			zeitdatumschreibenTIME();
			delay(50);
		}			
		if ((x<303 && x>272) && (y>54 && y<85))		//Secunde +
		{
			Serial.println("Secunde+");
			if (second>=59)
			{
				if (minute>=59)
			{
				if (hour>=23)
				{
					minute=0;
					hour=0;
					getDOM(month);
					if (dayOfMonth >= tagemonat)
					{
						dayOfMonth=1;
						if (month >=12)
						{
							month=1;
							year++;
						}
						else
						{
							month=month+1;
						}								
					}
					else
					{
						dayOfMonth=dayOfMonth+1;
					}				
				
				}
				else
				{
					hour++;
					minute=0;
				}					
				
			}				
			else
			minute++;
			second=0;	
			}
			else
			second++;			
			
			zeitdatumschreibenTIME();
			delay(50);
		}		
		
		
		
													//Datum Uhrzeit Stellen zurück
		
		if ((x<47 && x>16) && (y>110 && y<141))		//Tag -
		{
			Serial.println("Tag-");
			if (dayOfMonth <=1)
			{
				if (month <= 1)
				{
					month=12;
					if (year<=0)
					year=99;
					else
					year--;
					getDOM(month);
					dayOfMonth=tagemonat;
				}
				else
				{
					month--;
					getDOM(month);
					dayOfMonth=tagemonat;
				}												
			}
			else
			{
				dayOfMonth=dayOfMonth-1;
			}				
			zeitdatumschreibenTIME();
			delay(50);
		}		
		if ((x<95 && x>64) && (y>110 && y<141))		//Monat -
		{
			Serial.println("Monat-");
			if (month <=1)
				{
					month=12;
					if (year<=0)
					year=99;
					else
					year--;
				}
				else
				{
					month--;
				}			
			zeitdatumschreibenTIME();
			delay(50);
		}
		if ((x<143 && x>112) && (y>110 && y<141))		//Jahr -
		{
			Serial.println("Jahr-");
			if (year<=0)
			year=99;
			else
			year--;
			zeitdatumschreibenTIME();
			delay(50);
		}	
		if ((x<207 && x>176) && (y>110 && y<141))		//Stunde -
		{
			Serial.println("Stunde-");
			
			if (hour<=0)
			{
				hour=23;
				if (dayOfMonth <=1)
				{
					if (month <= 1)
					{
						month=12;
						if (year<=0)
						year=99;
						else
						year--;
						getDOM(month);
						dayOfMonth=tagemonat;
					}
					else
					{
						month--;
						getDOM(month);
						dayOfMonth=tagemonat;
					}												
				}
				else
				{
					dayOfMonth=dayOfMonth-1;
				}				
			}
			else
			hour--;			

			
			zeitdatumschreibenTIME();
			delay(50);
		}	
		
		if ((x<255 && x>224) && (y>110 && y<141))		//Minute -
		{
			Serial.println("Minute-");
			if (minute<=0)
			{
				minute=59;
				if (hour<=0)
				{
					hour=23;
					if (dayOfMonth <=1)
					{
						if (month <= 1)
						{
							month=12;
							if (year<=0)
							year=99;
							else
							year--;
							getDOM(month);
							dayOfMonth=tagemonat;
						}
						else
						{
							month--;
							getDOM(month);
							dayOfMonth=tagemonat;
						}												
					}	
					else
					{
						dayOfMonth=dayOfMonth-1;
					}				
				}
				else
				hour--;
				}
			else
			minute--;			
			
			
			
			zeitdatumschreibenTIME();
			delay(50);
		}			
		if ((x<303 && x>272) && (y>110 && y<141))		//Secunde -
		{
			Serial.println("Secunde-");
			if (second<=0)
			{
				second=59;
				if (minute<=0)
				{
					minute=59;
					if (hour<=0)
					{
						hour=23;
						if (dayOfMonth <=1)
						{
							if (month <= 1)
							{
								month=12;
								if (year<=0)
								year=99;
								else
								year--;
								getDOM(month);
								dayOfMonth=tagemonat;
							}
							else
							{
								month--;
								getDOM(month);
								dayOfMonth=tagemonat;
							}												
						}	
						else
						{
							dayOfMonth=dayOfMonth-1;
						}				
					}
					else
					hour--;
					}
				else
				minute--;		
				}
				else
				second--;			
				
			
			zeitdatumschreibenTIME();
			delay(50);
		}	
			
	}	
	else if(page == 4)		//Page 2 ist die Ende Stellen seite
	{
		if ((x<70 && x>0) && (y>160 && y<230))	//EXIT MENUE
		{
			menue();
			Serial.println("EXIT");
			delay(50);
		}
		if ((x<300 && x>250) && (y>160 && y<230))		//Uhr Stellen
		{
			Serial.println("SAVE DATA TO EPROM");
			msg("ENDE SAVE");
			EEPROM.write(1, second2);  //Secunden  
			EEPROM.write(2, minute2);  //minuten
			EEPROM.write(3, hour2);  //Stunden
			EEPROM.write(4, dayOfMonth2);  //Tag
			EEPROM.write(5, month2);  //Monat
			EEPROM.write(6, year2);  //Jahr
			Serial.println("Daten Gespeichert!!");
			delay(50);
			msg("DONE");
			endestellen();
		}
		
																//Buttons um die Zeit und das Datum zu ändern
		if ((x<47 && x>16) && (y>54 && y<85))		//Tag +
		{
			Serial.println("Tag+");
			getDOM(month);
			if (dayOfMonth2 >= tagemonat)
			{
				dayOfMonth2=1;
				if (month2 >=12)
				{
					month2=1;
					year2++;
				}
				else
				{
					month2=month2+1;
				}								
			}
			else
			{
				dayOfMonth2=dayOfMonth2+1;
			}						
			zeitdatumschreibenENDE();
			delay(50);
		}		
		if ((x<95 && x>64) && (y>54 && y<85))		//Monat +
		{
			Serial.println("Monat+");
			if (month2 >=12)
				{
					month2=1;
					year2++;
				}
				else
				{
					month2++;
				}				
			zeitdatumschreibenENDE();
			delay(50);
		}
		if ((x<143 && x>112) && (y>54 && y<85))		//Jahr +
		{
			Serial.println("Jahr+");
			if (year2 >=99)
			{
				year2=0;
			}
			else			
			year2++;
			zeitdatumschreibenENDE();
			delay(50);
		}	
		if ((x<207 && x>176) && (y>54 && y<85))		//Stunde +
		{
			Serial.println("Stunde+");
			if (hour2>=23)
			{
				hour2=0;
				getDOM(month2);
				if (dayOfMonth2 >= tagemonat)
				{
					dayOfMonth2=1;
					if (month2 >=12)
					{
						month2=1;
						year2++;
					}
					else
					{
						month2=month2+1;
					}								
				}
				else
				{
					dayOfMonth2++;
				}				
				
			}
			else
			hour2++;			
			zeitdatumschreibenENDE();
			delay(50);
		}	
		
		if ((x<255 && x>224) && (y>54 && y<85))		//Minute +
		{
			Serial.println("Minute+");
			
			if (minute2>=59)
			{
				if (hour2>=23)
				{
					minute2=0;
					hour2=0;
					getDOM(month2);
					if (dayOfMonth2 >= tagemonat)
					{
						dayOfMonth2=1;
						if (month2 >=12)
						{
							month2=1;
							year2++;
						}
						else
						{
							month2++;
						}								
					}
					else
					{
						dayOfMonth2++;
					}				
				
				}
				else
				{
					hour2++;
					minute2=0;
				}					
				
			}				
			else
			minute2++;
			
			zeitdatumschreibenENDE();
			delay(50);
		}			
		if ((x<303 && x>272) && (y>54 && y<85))		//Secunde +
		{
			Serial.println("Secunde+");
			if (second2>=59)
			{
				if (minute2>=59)
			{
				if (hour2>=23)
				{
					minute2=0;
					hour2=0;
					getDOM(month2);
					if (dayOfMonth2 >= tagemonat)
					{
						dayOfMonth2=1;
						if (month2 >=12)
						{
							month2=1;
							year2++;
						}
						else
						{
							month2++;
						}								
					}
					else
					{
						dayOfMonth2++;
					}				
				
				}
				else
				{
					hour2++;
					minute2=0;
				}					
				
			}				
			else
			minute2++;
			second2=0;	
			}
			else
			second2++;			
			
			zeitdatumschreibenENDE();
			delay(50);
		}		
		
		
		
													//Datum Uhrzeit Stellen zurück
		
		if ((x<47 && x>16) && (y>110 && y<141))		//Tag -
		{
			Serial.println("Tag-");
			if (dayOfMonth2 <=1)
			{
				if (month2 <= 1)
				{
					month2=12;
					if (year2<=0)
					year2=99;
					else
					year2--;
					getDOM(month2);
					dayOfMonth2=tagemonat;
				}
				else
				{
					month2--;
					getDOM(month2);
					dayOfMonth2=tagemonat;
				}												
			}
			else
			{
				dayOfMonth2--;
			}				
			zeitdatumschreibenENDE();
			delay(50);
		}		
		if ((x<95 && x>64) && (y>110 && y<141))		//Monat -
		{
			Serial.println("Monat-");
			if (month2 <=1)
				{
					month2=12;
					if (year2<=0)
					year2=99;
					else
					year2--;
				}
				else
				{
					month2--;
				}			
			zeitdatumschreibenENDE();
			delay(50);
		}
		if ((x<143 && x>112) && (y>110 && y<141))		//Jahr -
		{
			Serial.println("Jahr-");
			if (year2<=0)
			year2=99;
			else
			year2--;
			zeitdatumschreibenENDE();
			delay(50);
		}	
		if ((x<207 && x>176) && (y>110 && y<141))		//Stunde -
		{
			Serial.println("Stunde-");
			
			if (hour2<=0)
			{
				hour2=23;
				if (dayOfMonth2 <=1)
				{
					if (month2 <= 1)
					{
						month2=12;
						if (year2<=0)
						year2=99;
						else
						year2--;
						getDOM(month2);
						dayOfMonth2=tagemonat;
					}
					else
					{
						month2--;
						getDOM(month2);
						dayOfMonth2=tagemonat;
					}												
				}
				else
				{
					dayOfMonth2--;
				}				
			}
			else
			hour2--;			

			
			zeitdatumschreibenENDE();
			delay(50);
		}	
		
		if ((x<255 && x>224) && (y>110 && y<141))		//Minute -
		{
			Serial.println("Minute-");
			if (minute2<=0)
			{
				minute2=59;
				if (hour2<=0)
				{
					hour2=23;
					if (dayOfMonth2 <=1)
					{
						if (month2 <= 1)
						{
							month2=12;
							if (year2<=0)
							year2=99;
							else
							year2--;
							getDOM(month2);
							dayOfMonth2=tagemonat;
						}
						else
						{
							month2--;
							getDOM(month2);
							dayOfMonth2=tagemonat;
						}												
					}	
					else
					{
						dayOfMonth2--;
					}				
				}
				else
				hour2--;
				}
			else
			minute2--;			
			
			
			
			zeitdatumschreibenENDE();
			delay(50);
		}			
		if ((x<303 && x>272) && (y>110 && y<141))		//Secunde -
		{
			Serial.println("Secunde-");
			if (second2<=0)
			{
				second2=59;
				if (minute2<=0)
				{
					minute2=59;
					if (hour2<=0)
					{
						hour2=23;
						if (dayOfMonth2 <=1)
						{
							if (month2 <= 1)
							{
								month2=12;
								if (year2<=0)
								year2=99;
								else
								year2--;
								getDOM(month2);
								dayOfMonth2=tagemonat;
							}
							else
							{
								month2--;
								getDOM(month2);
								dayOfMonth2=tagemonat;
							}												
						}	
						else
						{
							dayOfMonth2--;
						}				
					}
					else
					hour2--;
					}
				else
				minute2--;		
				}
				else
				second2--;			
				
			
			zeitdatumschreibenENDE();
			delay(50);
			}	
			
		}
		else if(page == 5)		//Page 5 Frabe setup
			{
				if ((x<70 && x>0) && (y>160 && y<230))	//EXIT MENUE
				{
					menue();
					Serial.println("EXIT");
					delay(50);
				}
				if ((x<300 && x>250) && (y>160 && y<230))		//Farben Speichern
				{
					Serial.println("SAVE Farbe to EEPROM");
					msg("Farbe SAVE...");
					EEPROM.write(7, BGR);
					EEPROM.write(8, BGG);
					EEPROM.write(9, BGB);
					EEPROM.write(10, CR);
					EEPROM.write(11, CG);
					EEPROM.write(12, CB);
					msg("Save on EEPROM");
					delay(50);
					farbe();
				}	
				
				if ((x<47 && x>16) && (y>54 && y<85))		//BGR +
		{
			Serial.println("BGR+");
			BGR++;
			farbenDaten();
			delay(50);
		}		
		if ((x<95 && x>64) && (y>54 && y<85))		//BGG +
		{
			Serial.println("BGG+");
			BGG++;
			farbenDaten();
			delay(50);
		}
		if ((x<143 && x>112) && (y>54 && y<85))		//BGB +
		{
			Serial.println("BGB+");
			BGB++;
			farbenDaten();
			delay(50);
		}	
		if ((x<207 && x>176) && (y>54 && y<85))		//CR +
		{
			Serial.println("CR+");
			CR++;
			farbenDaten();
			delay(50);
		}	
		
		if ((x<255 && x>224) && (y>54 && y<85))		//CG +
		{
			Serial.println("CG+");
			CG++;
			farbenDaten();
			delay(50);
		}			
		if ((x<303 && x>272) && (y>54 && y<85))		//CB +
		{
			Serial.println("CB+");
			CB++;
			farbenDaten();
			delay(50);
		}		
		if ((x<47 && x>16) && (y>110 && y<141))		//BGR -
		{
			Serial.println("BGR-");
			BGR--;
			farbenDaten();
			delay(50);
		}		
		if ((x<95 && x>64) && (y>110 && y<141))		//BGG -
		{
			Serial.println("BGG-");
			BGG--;
			farbenDaten();
			delay(50);
		}
		if ((x<143 && x>112) && (y>110 && y<141))		//BGB -
		{
			Serial.println("BGB-");
			BGB--;
			farbenDaten();
			delay(50);
		}	
		if ((x<207 && x>176) && (y>110 && y<141))		//CR -
		{
			Serial.println("CR-");
			CR--;
			farbenDaten();
			delay(50);
		}	
		
		if ((x<255 && x>224) && (y>110 && y<141))		//CG -
		{
			Serial.println("CG-");
			CG--;
			farbenDaten();
			delay(50);
		}			
		if ((x<303 && x>272) && (y>110 && y<141))		//CB -
		{
			Serial.println("CB-");
			CB--;
			farbenDaten();
			delay(50);
		}	
				
			}			
	}
}