Don't know how to work with touch screen...


I am using Arduino MEGA 2560 with utft screen(touch screen is already included) -

Also I’m using this library to init utft screen and touch screen :

The question is : how can I get if the rectangle was touched?

#include <UTFT.h>
#include <ITDB02_Touch.h>
#include <SD.h>

// Declare which fonts we will be using
extern uint8_t SmallFont[];
extern uint8_t BigFont[];

UTFT screen(ITDB32S,A1,A2,A0,A3);
ITDB02_Touch  tscreen(13,10,11,12,9);

boolean welcome = true;

void setup() {

void loop() {
   if (welcome) {
   screen.fillRect( 20,20,60,60); //How can I get if this rect was touched?

I have not programmed touch screens, but I can help you. (I have programmed a lot of small games for PCs)

Everytime when I wanted to get that an object is clicked and mouse got above it I was comparing actual position of mouse X and Y. I think that applies too for touchscreen. Try to compare the position of touched finger with position of rectangle (X and Y ofc)

Well, I programming apps for PC too, and commands like getX or getY are just don't wont to work.(screen.print((String)(touchscreen.getX()), LEFT, 100):wink:

Why they won't work? I'm wondering that its what are you looking for.


I am having problems with Touch Screen too.
I am using a MEGA 2560 board interfaced to a Smart GPU2 touch screen. There are examples that are used
for the Ardunio UNO. But none of them work with the MEGA 2560. My interface is good. I have used wires
to connect the boards to each other.
When I try any of the examples, it gives me an error message for the line SMARTGPU2 lcd;

“GPU_Interface:29: error: ‘SMARTGPU2’ does not name a type”.

I am using Ardunio program version 1.5.6. The 1.05 version does not provide any error message and does not do anything either.

These lines are in every example;
#include <SMARTGPU2.h>

void setup() {


I have copied the GPU2 Library files into the Ardunio Library directory.
I appreciate any help possible.

Thank You

I think, that Your screen need to be initialized. Try to add "(10, 9)" after Your SMARTGPU2.
9 AND 10 are ports for connecting a screen, I guess...