Touchscreen sketch not responding to button press

Hello,

New to the arduino thing, but I’m learning everything is pretty much done for you, the difficulty I am having is finding what works with your hardware.

I’m building a generator and I decided to control it with an arduino touch screen and some relays. (switching larger solidstate relays with the small arduino relays of course)

I am able to draw buttons on the screen and sense where I am touching (output to serial monitor), however, for example, I want the button to change colors while I am pressing it. It does appear that the touch coordinates are referenced from a different corner than the drawing coordinates.

I though maybe the screen update was slow so I added a long delay after changing the button color, but still no luck.

Currently I have the sketch configured (supposedly) to turn the screen black when I press the green glow plug button. But no luck

Suggestions?

Thanks

sketch_dec13c.ino (2.61 KB)

The frame of reference may be different between the tft screen and the touch screen part.
For example, the tft screen may be 240 high by 360 long with origin top left. The touch screen may be 400 by 400 and glued on in such a way that the origin is on the bottom right. So you have to work out the mapping between the 2 frames of reference. The commented out function bool Touch_getXY(void) in your code appears like it attempted to do this.
What may help is drawing a small circle on the tft screen at the coordinates it gets from the touch screen so you can begin to understand what is happening.

Ok, Thanks. I was able to get the coordinates close by using that map function you noticed was commented out. The screen still will not turn back when I press the region defined by the button. Serial monitor only outputs when I touch in the desired region, so I know I am atleast getting into that part of the if loop where I have requested the screen turn black.

I guess then that no tft commands work in the loop.

Some screens, especially parallel connected ones, use up most of the arduino pins including D0 and D1 which are also used for serial activity such as writing to the arduino console.

I suppose you could try commenting out the Serial.print statements now that you know in principle that the touch part works to see if you get any further.

Post a link to your screen and any tutorial that you are following and state how it is wired and maybe you get further suggestions.

It is much easier to paste a small sketch into a CODE window. Format it with ctrl-T. You will get much more response from readers.

It is painful when you attach INO files.

Please study the examples that come with the library. They should all work 100%.
Adapt them to suit your project.

Ask when you have a problem. You appear to be commenting working code and replacing with garbage.

David.

If you still have a problem, this works

TSPoint p = ts.getPoint();
 pinMode(A1, OUTPUT);
 pinMode(A2, OUTPUT);

you need to put pinmode after TSPoint