RTCLib and touch screen on arduino uno for aquarium project

Serial.print(dispx)=320
Serial.print(dispy)=240

I was sur about that because i have done a general display menu before attacking touch screen part. And the position was between [0;0] and [320;240] ^^

So this mean with x and y =display x' and y'=touch screen

x=0 x'=200
x=320 x'=870

y=0 y'=250
y=240 y'=900

I find that strande bcause for a screen array of 240 (on y) i have 650 points on touch screen and for an array of 320(on x) i have 670 points. This means that it's more accurate on y than on x? Or i missed something. I guess for the box position i just have to make a mapping now.

Ok !! this seems to work : i have done a mapping and found coefficient to convert pixel to touch screen coordonate. But now i have a strange problem i can't understand. In the loop i setted up the HOME touch screen button. This Button will be use to change dispaly to the main menu (from parameters menu). When i click it the SErial communicate "we made it" meaning we passed the condition to close the parameter menu. Then it should do a clear screen and set the back all in black to clear the old menu but nothing happened. I set up a Serial.print after clear screen and myGLCD.fillRect and surprise.... Serial tell me Dafuq each 2000ms as he is supposed to do, but nothing change on the screen. Here is the loop and void code. :

void temps_parametres(){
  
  startup();
  int a=1;
  myGLCD.print("Leve Soleil : ",20,30);
  myGLCD.print(":", 155,30);
  myGLCD.print("Couche Soleil : ",20,80);
  myGLCD.print(":", 155,80);
  myGLCD.print("Leve Lune : ",20,130);
  myGLCD.print(":",155,130);
  myGLCD.print("Couche Lune : ", 20,180);
  myGLCD.print(":", 155,180);
  myGLCD.printNumI(lsh,140,30, 2, '0');
  myGLCD.printNumI(lsm,170,30, 2, '0');
  
  myGLCD.printNumI(csh,140,80, 2, '0');
  myGLCD.printNumI(csm,170,80, 2, '0');
  
  myGLCD.printNumI(llh,140,130, 2, '0');
  myGLCD.printNumI(llm,170,130, 2, '0');
  
  myGLCD.printNumI(clh,140,180, 2, '0');
  myGLCD.printNumI(clm,170,180, 2, '0');
  do
  {
  tp = myTouch.getPoint();
  if (tp.x<=240 && tp.x>=200 && tp.y<=50 && tp.y>=10)
    {
      if(lsm==59){
        if(lsh==23)
          {lsh=0;
           lsm=0;
          }
        else{lsh=lsh+1;}
      }
      else{lsm=lsm+1;}
     myGLCD.printNumI(lsh,140,30, 2, '0');
     myGLCD.printNumI(lsm,170,30, 2, '0');           
    }
  if (tp.x<=240 && tp.x>=200 && tp.y<=100 && tp.y>=60)
    {
      if(csm==59){
        if(csh==23)
          {csh=0;
           csm=0;
          }
        else{csh=csh+1;}
      }
      else{csm=csm+1;}
      myGLCD.printNumI(csh,140,80, 2, '0');
      myGLCD.printNumI(csm,170,80, 2, '0');   
    }
  if (tp.x<=240 && tp.x>=200 && tp.y<=150 && tp.y>=110)
    {
      if(llm==59){
        if(llh==23)
          {llh=0;
           llm=0;
          }
        else{llh=llh+1;}
      }
      else{llm=llm+1;}
     myGLCD.printNumI(llh,140,130, 2, '0');
     myGLCD.printNumI(llm,170,130, 2, '0');  
    }
  if (tp.x<=160 && tp.x>=0 && tp.y<=200 && tp.y>=160)
    {
      if(clm==59){
        if(clh==23)
          {clh=0;
           clm=0;
          }
        else{clh=clh+1;}
      }
      else{clm=clm+1;}
      myGLCD.printNumI(clh,140,180, 2, '0');
      myGLCD.printNumI(clm,170,180, 2, '0');   
    }     
  if (tp.x<=300 && tp.x>=260 && tp.y<=50 && tp.y>=10)
    {
      if(lsm==0){
        if(lsh==0)
          {lsh=23;
           lsm=59;
          }
        else{lsh=lsh-1;lsm=59;}
      }
      else{lsm=lsm-1;}
     myGLCD.printNumI(lsh,140,30, 2, '0');
     myGLCD.printNumI(lsm,170,30, 2, '0');               
    }
  if (tp.x<=300 && tp.x>=260 && tp.y<=100 && tp.y>=60)
    {
      if(csm==0){
        if(csh==0)
          {csh=23;
           csm=59;
          }
        else{csh=csh-1;csm=59;}
      }
      else{csm=csm-1;}
      myGLCD.printNumI(csh,140,80, 2, '0');
      myGLCD.printNumI(csm,170,80, 2, '0');               
    }
  if (tp.x<=300 && tp.x>=260 && tp.y<=150 && tp.y>=110)
    {
      if(llm==0){
        if(llh==0)
          {llh=23;
           llm=59;
          }
        else{llh=llh-1;llm=59;}
      }
      else{llm=llm-1;}
     myGLCD.printNumI(llh,140,130, 2, '0');
     myGLCD.printNumI(llm,170,130, 2, '0'); 
    }
  if (tp.x<=300 && tp.x>=260 && tp.y<=200 && tp.y>=160)
    {
      if(clm==0){
        if(clh==0)
          {clh=23;
           clm=59;
          }
        else{clh=clh-1;clm=59;}
      }
      else{clm=clm-1;}               
    }
    myGLCD.printNumI(clh,140,180, 2, '0');
    myGLCD.printNumI(clm,170,180, 2, '0');   
       
  if (tp.x<=619 && tp.x>=284.25 && tp.y<=900 && tp.y>=750)
  {
    Serial.print("We Made It !! \n");
    a=0;
  }
  
  }while (a==1);
 myGLCD.clrScr();
}
void loop() {
    if(tp.x<=160 && tp.x>=0 && tp.y<=20 && tp.y>=0 && state==false)
      {
       state=true;
      };
      
    if (state == true)
    {
    temps_parametres();
    state=false;
    };
    myGLCD.setColor(255,255,255);
    myGLCD.fillRect(0,dispx,0,dispy);
    Serial.print("Dafuq \n");
    delay(2000);
}

EDIT : mapping to convert display position to touch screen position is a bit harder than i thought. I have luck that it worked for home button but when i tryed to do the same for all the 8 others ones, it didn't workes and i understood that i can't find a constant coefficient to link the 2 parameters. IF someone is inspired let me know.

2nd Edit : Finally done the mapping by testing each corne of each button and writing coordonates. Unfortunately i have the same problem as before : The screen can't be modify. I mean it detects when i say "+" to a parameter Serial.print send the good new number of the parameter but as if i put right after myGLCD.print(the new number at the same place as the old) nothing happen.....

3rd Edit : For now i have to add myGLCD.Init before cleaning screen or making any change.... This is hard..... i need help lol

Still didn't fix this issue.... I have to do a myGLCD.Init and a myGLCD.ClrScr to have my new menu.... This is annoying because the white blink is really long :((

Can't fix this damn issue. I have to init screen before a clear screen in order to change it. This is really annoying. I'm still working on the code i will post it later when the only thing left will be to solve this damn thing.

up

There's no way I'm going to plow through a bunch of cryptically named variables and uncommented code to help you - and I'm sure most of the people who could help you will feel the same.

Ok, sorry, i will try to clean it up and then i will post it back.

Hello here comes a cleaner version with comments in english :

#include <Adafruit_GFX.h>
#include <UTFTGLUE.h>
#include <SPI.h>
#include <MCUFRIEND_kbv.h>
#include <RTClib.h>
#include <Wire.h>
#include <avr/pgmspace.h>

MCUFRIEND_kbv tft;

RTC_DS1307 rtc;

#include <TouchScreen.h>
#define YP A1
#define YM 7
#define XM A2
#define XP 6
UTFTGLUE myGLCD(0x7781, A2, A1, A3, A3, A0);


// Assign human-readable names to some common 16-bit color values:
#define BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF

//Screen width and height
int dispx, dispy;

//boolean allowing settings menu opening 
bool state = true;

//Variable allowing to know if menu has to be refresh or not
int refresh=0;

//Token goes to 0 when we need to leave settings menu loop
int a;

//Token to know if previous display was setting or menu (if b=1 it means that home screen was the last displayed so we don't need to refresh it
int b = 0;

//Variable following the differents hours/minutes of setings 
//Sun rise
long lsh = 17;
long lsm = 0;
//Sunset
long csh = 22;
long csm = 0;
//Moon rise
long llh = 0;
long llm = 0;
//Moon set
long clh = 2;
long clm = 30;

//Hour, minutes, seconds RTC
int h, m, s;


extern uint8_t SmallFont[];
extern uint8_t BigFont[];
extern uint8_t SevenSegNumFont[];


#define TOUCH_ORIENTATION  LANDSCAPE

TouchScreen myTouch(XP, YP, XM, YM, 300);
TSPoint tp;



// Void creating + and - butons (used in settings menu)
void Boutons(int x, int y)
{
  myGLCD.setColor(0, 255, 0);
  
  myGLCD.drawRect(x, y + 20, x + 40, y - 20);
  myGLCD.drawRect(x + 60, y + 20, x + 100, y - 20);
  //+
  myGLCD.drawLine(x + 10, y, x + 30, y);
  myGLCD.drawLine(x + 20, y + 10, x + 20, y - 10);
  //-
  myGLCD.drawLine(x + 70, y, x + 90, y);

}

//Get hour from RTC
void get_heure(int h, int m, int s)
{
  DateTime now = rtc.now();
  m = int(now.minute());
  h = int(now.hour());
  s = int(now.second());
  Serial.print(h);
  Serial.print("\n");
  Serial.print(m);
  Serial.print("\n");
}

// Bool allowing to know if touch screen has been pressed on home box
bool menu_parametres()
{
  tp = myTouch.getPoint();
  if (tp.x <= 680 && tp.x >= 400 && tp.y <= 900 && tp.y >= 820 && tp.z >= 50 && state == false)
  {
    return true;
  }
  else
  {
    return false; 
  }

}


//Detect wich button has been pressed on touch screen (8 differents buttons)

void detection_boutons()
{
   tp = myTouch.getPoint();
    if (tp.x <= 720 && tp.x >= 630 && tp.y <= 315 && tp.y >= 210 && tp.z > 50)
    {
    if (lsm == 59) {
      if (lsh == 23)
      { lsh = 0;
        lsm = 0;
      }
      else {
        lsh = lsh + 1;
      }
    }
    else {
      lsm = lsm + 1;
    }
    refresh=1;
    }

  if (tp.x <= 720 && tp.x >= 630 && tp.y <= 475 && tp.y >= 370 && tp.z > 50)
  {
    if (csm == 59) {
      if (csh == 23)
      { csh = 0;
        csm = 0;
      }
      else {
        csh = csh + 1;
      }
    }
    else {
      csm = csm + 1;
    }
    refresh=1;
  }


  if (tp.x <= 720 && tp.x >= 630 && tp.y <= 630 && tp.y >= 510 && tp.z > 50)
  {
    if (llm == 59) {
      if (llh == 23)
      { llh = 0;
        llm = 0;
      }
      else {
        llh = llh + 1;
      }
    }
    else {
      llm = llm + 1;
    }
    refresh=1;
  }


  if (tp.x <= 720 && tp.x >= 630 && tp.y <= 790 && tp.y >= 680 && tp.z > 50)
  {
    if (clm == 59) {
      if (clh == 23)
      { clh = 0;
        clm = 0;
      }
      else {
        clh = clh + 1;
      }
    }
    else {
      clm = clm + 1;
    }
    refresh=1;
  }

  if (tp.x <= 860 && tp.x >= 770 && tp.y <= 315 && tp.y >= 210 && tp.z > 50)
  {
    if (lsm == 0) {
      if (lsh == 0)
      { lsh = 23;
        lsm = 59;
      }
      else {
        lsh = lsh - 1;
        lsm = 59;
      }
    }
    else {
      lsm = lsm - 1;
    }
    refresh=1;
  }
  if (tp.x <= 860 && tp.x >= 770 && tp.y <= 475 && tp.y >= 370 && tp.z > 50)
  {
    if (csm == 0) {
      if (csh == 0)
      { csh = 23;
        csm = 59;
      }
      else {
        csh = csh - 1;
        csm = 59;
      }
    }
    else {
      csm = csm - 1;
    }
    refresh=1;
  }
  if (tp.x <= 860 && tp.x >= 770 && tp.y <= 630 && tp.y >= 510 && tp.z > 50)
  {
    if (llm == 0) {
      if (llh == 0)
      { llh = 23;
        llm = 59;
      }
      else {
        llh = llh - 1;
        llm = 59;
      }
    }
    else {
      llm = llm - 1;
    }
    refresh=1;
  }
  if (tp.x <= 860 && tp.x >= 770 && tp.y <= 790 && tp.y >= 680 && tp.z > 50)
  {
    if (clm == 0) {
      if (clh == 0)
      { clh = 23;
        clm = 59;
      }
      else {
        clh = clh - 1;
        clm = 59;
      }
    }
    else {
      clm = clm - 1;
    }
    refresh=1;
  };


  //Button to go back to home menu
  if (tp.x <= 680 && tp.x >= 400 && tp.y <= 900 && tp.y >= 820 && tp.z > 20)
  {
    Serial.print("We Made It !! \n"); //Just a serial print to let me know if all is ok
    a = 0; // a=0 allows to leave do while loop
  };
}


//Home screen

void ecran_home()
{
  //get_heure(h,m,s);    //Can't use it for the moment
  if (b == 1) // If we come from settings menu we have to display everything again. 
  {
    myGLCD.fillScr(0, 0, 0);
    myGLCD.setColor(0, 250, 0);
    myGLCD.setColor(150, 0, 175);
    myGLCD.fillRect(100, 200, 220, 240);
    myGLCD.setColor(255, 255, 255);
    myGLCD.setBackColor(150, 0, 175);
    myGLCD.print("PARAMETRES", 130, 215);
    myGLCD.setBackColor(0, 0, 0);
  };
    myGLCD.setColor(255, 255, 255);
    myGLCD.printNumI(17, 140, 120, 2, "0");  //Supposed to be h
    myGLCD.print(":", 160, 120);
    myGLCD.printNumI(4, 180, 120, 2, "0");   //Supposed to be m
}


// Settings screen

void ecran_parametres()
{

  refresh=1; 
  a = 1; //a is now 1 to let know in home menu that we come from settings screen

  do
  {
    if (refresh==1)
    {

     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     ///////////////The Damn bug force the us of init and clear screen to modify the display..../////////////////////
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
      
     myGLCD.InitLCD(TOUCH_ORIENTATION);
     myGLCD.fillScr(0, 0, 0);


     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////


     //Drawing the 4 lines of buttons + and -
     Boutons(200, 30);
     Boutons(200, 80);
     Boutons(200, 130);
     Boutons(200, 180);

     //Drawing home button
     myGLCD.setColor(150, 0, 175);
     myGLCD.fillRect(100, 200, 220, 240);
     myGLCD.setColor(255, 255, 255);
     myGLCD.setBackColor(150, 0, 175);
     myGLCD.print("HOME", 148, 215);
     myGLCD.setBackColor(0, 0, 0);

     //Printing the different settings name
     myGLCD.print("Leve Soleil : ", 20, 30);
     myGLCD.print(":", 155, 30);
     myGLCD.print("Couche Soleil : ", 20, 80);
     myGLCD.print(":", 155, 80);
     myGLCD.print("Leve Lune : ", 20, 130);
     myGLCD.print(":", 155, 130);
     myGLCD.print("Couche Lune : ", 20, 180);
     myGLCD.print(":", 155, 180);

     //Printing the different settings value 
     myGLCD.printNumI(lsh, 140, 30, 2, '0');
     myGLCD.printNumI(lsm, 170, 30, 2, '0');

     myGLCD.printNumI(csh, 140, 80, 2, '0');
     myGLCD.printNumI(csm, 170, 80, 2, '0');

     myGLCD.printNumI(llh, 140, 130, 2, '0');
     myGLCD.printNumI(llm, 170, 130, 2, '0');

     myGLCD.printNumI(clh, 140, 180, 2, '0');
     myGLCD.printNumI(clm, 170, 180, 2, '0');

     //Make refresh to 0
     refresh=0;
     
    };

    //If a button is pressed refresh goes to 1. And then all the display is refreshed. Because of the bug i can't modify just a line...
    detection_boutons(); 
    } while (a == 1);
}

baracuda33:
Hello here comes a cleaner version with comments in english :

You have all the same cryptic variable names. Shall I name some examples?

Rest of the code because too many caracters on previous post.

void setup() {
  //Init serial for diagnostics
  Serial.begin(9600);

  //Init wire and RTC lib // Can't use it because of the init bug...
  /*Wire.begin();
  rtc.begin();
  rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  DateTime now = rtc.now();
  
  //Serial test on RTC
  m = int(now.minute());
  h = int(now.hour());
  s = int(now.second());
  Serial.print(h);
  Serial.print("\n");
  Serial.print(m);
  Serial.print("\n");*/

  //Initialising LCD
  pinMode(A0, OUTPUT);
  digitalWrite(A0, HIGH);
  myGLCD.InitLCD(TOUCH_ORIENTATION);
  myGLCD.clrScr();

  dispx = myGLCD.getDisplayXSize();
  dispy = myGLCD.getDisplayYSize();

 }
 
void loop() {
  b = 0;
  Serial.print("depart");

  //If we need to go to settings
  if (state == true)
  {
    Serial.print("boucle parametres");
    ecran_parametres();
    myGLCD.InitLCD(TOUCH_ORIENTATION);
    myGLCD.clrScr();
    b = 1;
  };
  Serial.print("boucle home");
  ecran_home();

  //Test if settings button is pressed while home screen is displayed
  state = menu_parametres();
  Serial.print(state);
}

The main problem is on the Settings menu (void ecran_parametres). Indeed i can't modify the display with a clearscreen or by calling a myGLCD.print with a different value... I have to do a full refresh and initialisation. Same when i change menu, i have to do an initialisation again.
It makes long white cut but furthermore it crashes my RTC. Indeed when i do a LCD initialisation while RTC is active, i get a white screen (not totaly white i can't see the menu throught it). As if the screen was doing initialisation loops.

Just see your answer. Yes if you have questions do not hesitates. Indeed my variable names are not so clear, but i defined them in comments. I could try to change the name if you want like for the 2 tokens , a and b ^^. Or the settings parameters it's because i'm french :

lsh/lsm=Levé de Soleil Heure/minute (Sun rise hour/minute)

csh/csm=Couché de Soleil Heure/Minute (Sunset hour/minute)

llh/llm=Levé de Lune Heure/Minute (moon rise Hour/minute)

clh/clm= Couché de Lune Heure/Minute (moonset Hour/minute)

baracuda33:
Rest of the code because too many caracters on previous post.

As it explains in the forum posting guide, you can post code as an attachment if it is too large.

baracuda33:
ndeed my variable names are not so clear, but i defined them in comments. I could try to change the name if you want like for the 2 tokens , a and b ^^.

That forces a reader to go back and forth to the comments to know what they mean. Please do change a and b, it is a good example of what I am talking about.

It would be fine if the names are in French, even though it would not be as helpful for English speakers it would certainly help you, and any French speakers that read it.

like

lsh=LeveDeSoleilHeure

There is no benefit to abbreviations when the use of the variable is not restricted to a few closely located lines such as in a tiny for loop.

Sorry i didn't see that we can attached a file if the code it's too long. It's done. Btw i changed some of the variables to make it easier to understand.

TACTILE_WORKING.ino (9.3 KB)

It's possible that you are crashing the LCD driver by writing to locations off the screen, or giving it some other garbage command. Have a close look at that.

So what should i do? you think that the main problem is on this line :

UTFTGLUE myGLCD(0x7781, A2, A1, A3, A4, A0);

? I think indeed that their is a problem with the driver because it seems anormal that i have to do an other init. an other weird point is that i have try with a small loop and a 1000ms Delay to change time time on home menu. And the strange things is that it worked... Time was changing on the screen without any needs of refresh. But on the setting screen if i change a value it does not appear until i do a new init / Clearscreen.

This problem is here without RTC and with RTC it only add a white screen weird thing.

Remove all your functions one by one until you get a working sketch. Then add them back in one by one and debug each problem independently.

I tryed something just to check if the problem was coming from my code. I made a really simple code to display RTC time on screen :

#include <Adafruit_GFX.h>
#include <UTFTGLUE.h>
#include <SPI.h>
#include <MCUFRIEND_kbv.h>
#include <RTClib.h>
#include <Wire.h>
#include <avr/pgmspace.h>

MCUFRIEND_kbv tft;

RTC_DS1307 rtc;

#include <TouchScreen.h>
#define YP A1
#define YM 7
#define XM A2
#define XP 6
UTFTGLUE myGLCD(0x7783, A2, A1, A3, A4, A0);

#define TOUCH_ORIENTATION  LANDSCAPE

TouchScreen myTouch(XP, YP, XM, YM, 300);
TSPoint tp;

//Hour, minutes, seconds RTC
int h, m, s;

void setup() {
  //Init serial for diagnostics
  Serial.begin(9600);
  //Initialising LCD
  myGLCD.InitLCD(TOUCH_ORIENTATION);
  myGLCD.clrScr();
  myGLCD.fillScr(0,0,0);
  myGLCD.setColor(150,0,25);

  
  //Init wire and RTC lib .
  Wire.begin();
  rtc.begin();
  rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  DateTime now = rtc.now();
  
  //Serial test on RTC
  m = int(now.minute());
  h = int(now.hour());
  s = int(now.second());
  Serial.print(h);
  Serial.print("\n");
  Serial.print(m);
  Serial.print("\n");



}

void loop() {
      Serial.print("loop is on \n");
      DateTime now=rtc.now();
      m=int(now.minute());
      h=int(now.hour());
      s=int(now.second());
      myGLCD.printNumI(h,140,120,2,'0');
      myGLCD.print(":",150,120);
      myGLCD.printNumI(m,160,120,2,'0');
      myGLCD.printNumI(s,148,150);
      delay(1000);
}

White screen....I Guess the RTC is in Conflict with the damn LCD. How am I supposed to sold this Harware issue? RTC is plug on SCL and SDA pins and on 5v and Ground. LCD Use A4 as LCD_RST on the shield. But A4 is the SDA SIgnal too. Maybe this cause multiple reset on screen. The point is as if i change:

UTFTGLUE myGLCD(0x7783, A2, A1, A3, A4, A0);

to

UTFTGLUE myGLCD(0x7783, A2, A1, A3,10, A0);

It doesn't work (pin 10 is a pin used for SD card wich i don't use.

Can't i use Wire lib to select the adress of communication or someone has any ideas?

About the first problem wich was that i can't do a clear screen. I Found the problem with the following code :

#include <Adafruit_GFX.h>
#include <UTFTGLUE.h>
#include <SPI.h>
#include <MCUFRIEND_kbv.h>
#include <RTClib.h>
#include <Wire.h>
#include <avr/pgmspace.h>

MCUFRIEND_kbv tft;

RTC_DS1307 rtc;

#include <TouchScreen.h>
#define YP A1
#define YM 7
#define XM A2
#define XP 6
UTFTGLUE myGLCD(0x7783, A2, A1, A3, A4, A0);

#define TOUCH_ORIENTATION  LANDSCAPE

TouchScreen myTouch(XP, YP, XM, YM, 300);
TSPoint tp;

//Hour, minutes, seconds RTC
int h, m, s;


void RGB()
{
 delay(1000);
 myGLCD.fillScr(255,0,0);
 delay(1000);
 myGLCD.fillScr(0,255,0);
 delay(1000);
 myGLCD.fillScr(0,0,255);  
}

void PageMenu1()
{
  myGLCD.fillScr(0,0,0);

  //Ligne 1
  myGLCD.setColor(255,255,255);
  myGLCD.drawRect(200,50,240,10);
  myGLCD.drawRect(260,50,300,10);

  //Ligne 2
  myGLCD.drawRect(200,100,240,60);
  myGLCD.drawRect(260,100,300,60);

  //Ligne 3
  myGLCD.drawRect(200,150,240,110);
  myGLCD.drawRect(260,150,300,110);

  //Ligne 4
  myGLCD.drawRect(200,200,240,160);
  myGLCD.drawRect(260,200,300,160);

  //Buton Home
   myGLCD.setColor(150, 0, 175);
   myGLCD.fillRect(90, 200, 220, 240);
   myGLCD.setColor(255, 255, 255);
   myGLCD.setBackColor(150, 0, 175);
   myGLCD.print("HOME", 148, 215);
   myGLCD.setBackColor(0, 0, 0);

   delay(1000);
}

void PageMenu2()
{
  int minutes, secondes;
  int TokenExit=1;
  minutes=0;
  secondes=0;
  myGLCD.fillScr(0,0,0);
  myGLCD.setColor(255,255,255);

  //Button Menu1()
   myGLCD.setColor(0, 250, 0);
   myGLCD.setColor(150, 0, 175);
   myGLCD.fillRect(90, 200, 220, 240);
   myGLCD.setColor(255, 255, 255);
   myGLCD.setBackColor(150, 0, 175);
   myGLCD.print("PARAMETRES", 125, 215);
   myGLCD.setBackColor(0, 0, 0);
   myGLCD.print(":",150,120);
   
  do{
    myGLCD.setColor(0,0,0);
    myGLCD.fillRect(140,130,145,110);
    myGLCD.setColor(255,255,255);
    myGLCD.printNumI(minutes,140,120,2,"0");

    myGLCD.setColor(0,0,0);
    myGLCD.fillRect(155,130,175,110);
    myGLCD.setColor(255,255,255 );
    myGLCD.printNumI(secondes,160,120,2,"0");
    Serial.print(secondes);
    secondes=secondes+1;
    delay(1000);
    tp= myTouch.getPoint();
    if (tp.x <= 680 && tp.x >= 400 && tp.y <= 900 && tp.y >= 820 && tp.z > 20)
    {
    TokenExit = 0;
    };
  }while (TokenExit==1);
  Serial.print("we are out");
}

void setup() {
  //Init serial for diagnostics
  Serial.begin(9600);
  
  //Initialising LCD
  pinMode(A0, OUTPUT);
  digitalWrite(A0, HIGH);
  myGLCD.InitLCD(TOUCH_ORIENTATION);
  myGLCD.clrScr();
  myGLCD.fillScr(0,0,0);
  myGLCD.setColor(150,0,25);
  
  //Init wire and RTC lib .
 /*Wire.begin();
  rtc.begin();
  rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  DateTime now = rtc.now();
  
  //Serial test on RTC
  m = int(now.minute());
  h = int(now.hour());
  s = int(now.second());
  Serial.print(h);
  Serial.print("\n");
  Serial.print(m);
  Serial.print("\n");*/



}


void loop()
{
     RGB();
     PageMenu1();
     PageMenu2();    
}

The shit happens when i use the touch screen functions. If i comment this part all is good.