Experimentalist said:
Thanks for all the info. Which Touch library are you using?
Do you have any code you are willing to share?
Ex.
No problem at all
For touch I use the 'default'
Adafruit Touchscreen library
It worked perfectly right from the start, but I needed to do a little calibrating and re-orientate the touch.
The touchscreen uses portrait mode orientation, so does the display.
Since I wanted to use the screen in landscape mode, my code also has to incorporate the remapping of
x-touch coordinates to
y-screen coordinates and vice versa.
(I needed to modify the map() function for this)
A bit more important: in my case the TFT screen itself is a few pixels smaller than the touchlayer is.
A friend of mine build a simple testbed, which presses on the 4 outer pixels of the TFT screen, one after another.
After finding the touch x/y coordinates for the outer coordinates display, I applied these to the map() function and now I have 2px accuracy between display and touchlayer
(max off by 1px anywhere on the display).
(I needed to modify the TS_MINX>TS_MAXY values for this)
I still have to refine the test I initially did to get 100% accuracy, but this is working so well that it has a low priority on my to-do list.
More important stuff to get to!
I wanted to add my Touchscreen library as a zip file, but it appears I don't have the option in a PM to send attachments.
However, I have not modified the lib in any way, so you can download from the Adafruit link as well.
example of the code I used to remap the screen vs touchlayer:
Code:
#define MINPRESSURE 10 // minimum pressure required to register a hit
#define MAXPRESSURE 1000 // maximum pressure required to register a hit (otherwise it has fallen)
#define TS_MINX 110 // define edges of screen v.s. edges of touchlayer
#define TS_MINY 120 // this is ofcourse in PORTRAIT MODE
#define TS_MAXX 930 // later on, a conversion to landscape mode is initiated
#define TS_MAXY 935 // remember this while testing
void loop() {
Point p = ts.getPoint(); // a point p holds x y and z coordinates for touchscreen
touchx = map(p.y, TS_MINY, TS_MAXY, 0, tft.width()); // remap y coordinates of touch to x coordinates of screen
touchy = map(p.x, TS_MINX, TS_MAXX, tft.height(), 0); // remap y coordinates of touch to x coordinates of screen
if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {
// if pressure is high enough, go do stuff
}
}
The comments are mostly a reminder to myself, didn't bother to change them, I'm pretty sure you understand the code better than I do
Ow, something I found useful, if(pz < 1) means no pressure, so stuff can happen if there is no press, like a counter start running to dim/sleep the display after x sec.
Let me know if there is anything else I can do for you!