Help with coding of TFT LCD Touch!!!

Hi guys!!!

I have a problem with my touch. I have set the code so when you touch a point of the screen in page 1 it takes you to page 2. At page 2 at the same point of the screen there is an other statement that takes you back to page 1. The problem is that when I am at page 1 and touch that point of the screen it takes me to the page 2 and immediately takes me back to page 1. How is it possible to make it taking me to page 2 and stays there until I touch again the screen? I have tried putting a delay but it didn’t help. It took me again back to page 1 again but with the delay I programmed it.

here is the code:

#include <UTouch.h>
#include <UTouchCD.h>

#include <memorysaver.h>
#include <UTFT.h>



UTFT myGLCD(ITDB32S,38,39,40,41);
UTouch myTouch(6,5,4,3,2);

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

int led = 0;
int page = 0;
int x, y; 



void setup(){
  myGLCD.InitLCD(LANDSCAPE);
  myGLCD.clrScr();
  myTouch.InitTouch(LANDSCAPE);  
  myTouch.setPrecision(PREC_MEDIUM); 
  mainscr();
}

void loop(){
  if (true)
  {
    if (myTouch.dataAvailable())

    {
      myTouch.read();
      x=myTouch.getX();
      y=myTouch.getY();
      
      if (page == 1)
      {
        if ((x>=20) && (x<=170))
        {
          if ((y>=49) && (y<=65))
          {
            testpage2();
          }
        }
      }
      if (page == 2)
      {
        if ((x>=20) && (x<=170))
        {
          if ((y>=49) && (y<=65))
          {
            mainscr();
          }
        }
      }
    }
  }
}

void testpage2() {
  page = 2;
  myGLCD.clrScr();
  myGLCD.fillScr(0, 0, 0);
  myGLCD.setBackColor (0, 0, 0);
  myGLCD.setFont(SmallFont);
  myGLCD.setColor(255, 255, 255);
  myGLCD.print("TestButton", 25, 53);

}
          
          

      
      
void mainscr() {
  page = 1;
  myGLCD.fillScr(0, 0, 0);
  myGLCD.setBackColor (0, 0, 0);
  myGLCD.setFont(SmallFont);
  myGLCD.setColor(255, 255, 255);
  myGLCD.setBackColor (0, 0, 0);
  myGLCD.print("Enable LED", 25, 53);  
  
}

Hi chrispav

Try changing this ...

      if (page == 2)

to ...

      else if (page == 2)

Regards

Ray

That's it! It works! Thank you very much Ray!!! You are awesome!!!