Go Down

Topic: UTouch.h button detection [SOLVED] (Read 1 time) previous topic - next topic

rcullan

Mar 03, 2013, 02:07 pm Last Edit: Mar 03, 2013, 10:00 pm by rcullan Reason: 1
I am working on a project with touch LCD screen using the UTouch.h library.

Basically I am trying to detect a button, but I cant use a while statement because I need my program to run in the background without refreshing the screen.

So I am trying to do something like:

 if(myTouch.dataAvailable() == true) {
   myTouch.read();
   x=myTouch.getX();
   y=myTouch.getY();
 
   if(x >= 250 && x <= 293 && y >= 99 && y <= 119)
   {
     if(button1State == false) button1State = true;
     if(button1State == true) button1State = false;
   }
 }

Its not working though. Any tips?

rcullan

I was able to figure this one out on my own. The proper syntax for button detection is this.

  //Button Detection
  if (myTouch.dataAvailable())
    {
      myTouch.read();
      x=myTouch.getX();
      y=myTouch.getY();
      if (((y>=99) && (y<=119)) && ((x>=250) && (x<=293)))
      {
        if(button1State == false) {
          button1State = true;
          delay(50);  //delay for screen debounce
        } else {
          button1State = false;
          delay(50);  //delay for screen debounce
        }
      }
  }

Go Up