Pages: [1]   Go Down
Author Topic: UTouch.h button detection [SOLVED]  (Read 918 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
« Last Edit: March 03, 2013, 04:00:28 pm by rcullan » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
        }
      }
  }
Logged

Pages: [1]   Go Up
Jump to: