i've been successfully using my sainsmart 4.3" (SSD1963) with the UTFT, URtouch and UTFT_buttons libraries for complex stuff, but now i'm stuck to a very simple thing...
i use buttons throughout menus and everything works like a charm, but at a point i want an area on the screen where i can get the X and Y values of the touch point. that menu also has 3 buttons on it (outside the area i want to trace touch in) the problem is, if i use mytouch.getX or getY the values of the coordinates i get come in very very rarely even if i move my pen on the screen a lot.
=> if i comment out the "myTouch.checkbuttons()" line code executes blazingly fast (DUE) and i get the results i expect reported on the Serial output.
so what's happening in that line? are the coordinate values used up somewhere in the library and i can't use them for my own purpose too?
is there a workaround for this?
thank you... i will post some really simple code as soon as i get home!
Back with some really simple code to show what i mean... try this (replacing pinouts for your setup) :
#include <UTFT.h>
#include <URTouch.h>
#include <UTFT_Buttons.h>
extern uint8_t BigFont[];
UTFT myGLCD(ITDB43,38,39,40,41);
URTouch myTouch(43,45,47,49,51);
UTFT_Buttons myButtons(&myGLCD, &myTouch);
int button1,pressed_button;
void setup()
{
Serial.begin(115200);
myGLCD.InitLCD();
myGLCD.clrScr();
myTouch.InitTouch();
myTouch.setPrecision(PREC_MEDIUM);
button1 = myButtons.addButton( 10, 20, 300, 30, "Button 1");
myButtons.drawButtons();
}
void loop(){
if (myTouch.dataAvailable() == true){
myTouch.read();
int x = myTouch.getX();
int y = myTouch.getY();
Serial.print(x);
Serial.print("-");
Serial.println(y);
pressed_button = myButtons.checkButtons();
}
}
what is displayed on screen is irrelevant since we're now testing the getX and getY coordinates.
open the terminal and move your pen across the touch screen. numbers come out sparesly, and you mostly get -1.
now comment the line
pressed_button = myButtons.checkButtons();
and try again.
now the numbers come in fast and smooth like i would expect them to be...
so what's happening inside the checkButtons? why don't i have some nice numbers coming when i use it? has anyone run into the same problem?
I decided to open the black box i called library and see what's inside and there i found a "while" line which actually blocks the rest of the code until the touch is released (to avoid continuous presses i guess) so i commented it out and now everything works perfectly. To avoid the continuous touch activation i used a variable (outside the library code) which holds the button id and compares it with the just previous presses id. So code executes only when the id changes i can't believe it's finally working! That way i made my own slide bars with out any extra libraries
Thanks everyone!!!