Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 17:08 12 Jul 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : touch buttons

Author Message
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1989
Posted: 07:29pm 28 Jun 2015
Copy link to clipboard 
Print this post

I am upgrading a project to use a 2.8" TFT display. I have the display working OK and have set up the display the way I want. Previously I had 3 switches connected to interrupt pins. I now have 3 touch buttons on the screen, how do I monitor the buttons. I looked through Peter's demo code but couldn't find anything.
I know Geoff used the Touch(x) command but his small demo code ran so fast the touch could not be missed. With a large program it would almost certainly be doing something else during the touch.
PaulEdited by palcal 2015-06-30
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
viscomjim
Guru

Joined: 08/01/2014
Location: United States
Posts: 925
Posted: 03:19am 29 Jun 2015
Copy link to clipboard 
Print this post

Palcal, I recall seeing a post i believe it was from Zonker where he had a gauge set up on the lcd and it had a couple of buttons, that when you touched them they turned a different color. I can't find the thread now but may look around, I thought is was pretty cool and might help you.
 
CircuitGizmos

Guru

Joined: 08/09/2011
Location: United States
Posts: 1427
Posted: 04:43am 29 Jun 2015
Copy link to clipboard 
Print this post

Make a timed interrupt (Settick) and call touch. If x and y are -1 there has been no touch.



SETTICK 100, TouchInt, 1



TouchInt:
' Read touch
tX = TOUCH(X)
tY = TOUCH(Y)

' Test for valid touch
IF tX <> -1 AND tY <> -1 THEN
IF 8 < tX AND tX < 55 AND 56 < tY AND tY < 102 THEN
keypress = 1
ELSE IF 8 < tX AND tX < 55 AND 120 < tY AND tY < 165 THEN
keypress = 2
ELSE IF 8 < tX AND tX < 55 AND 185 < tY AND tY < 230 THEN
keypress = 3
ELSE IF 71 < tX AND tX < 119 AND 56 < tY AND tY < 102 THEN
keypress = 4
ELSE IF 71 < tX AND tX < 119 AND 120 < tY AND tY < 165 THEN
keypress = 5
ELSE IF 71 < tX AND tX < 119 AND 185 < tY AND tY < 230 THEN
keypress = 6
ELSE IF 135 < tX AND tX < 182 AND 56 < tY AND tY < 102 THEN
keypress = 7
ELSE IF 135< tX AND tX < 182 AND 120 < tY AND tY < 165 THEN
keypress = 8
ELSE IF 135 < tX AND tX < 182 AND 185 < tY AND tY < 230 THEN
keypress = 9
ELSE IF 200 < tX AND tX < 245 AND 56 < tY AND tY < 102 THEN
keypress = 10
ELSE IF 200 < tX AND tX < 245 AND 120 < tY AND tY < 165 THEN
keypress = 11
ELSE IF 200 < tX AND tX < 245 AND 185 < tY AND tY < 230 THEN
keypress = 12
ELSE IF 265 < tX AND tX < 308 AND 56 < tY AND tY < 102 THEN
keypress = 13
ELSE IF 265 < tX AND tX < 308 AND 120 < tY AND tY < 165 THEN
keypress = 14
ELSE IF 265 < tX AND tX < 308 AND 185 < tY AND tY < 230 THEN
keypress = 15
ELSE
keypress = 99
ENDIF

PRINT "key: " keypress

' Turn off TouchInt
SETTICK 0, 0, 1
ENDIF
IRETURN



From that bit of code the screen is divided into 15 parts/buttons. A touch sets keypress to a key value for the main program to deal with.


Micromites and Maximites! - Beginning Maximite
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1989
Posted: 11:11am 29 Jun 2015
Copy link to clipboard 
Print this post

Thanks, I understand that, will give it a go
I would also like to thank Geoff and especially Peter for his work on the TFT displays they make a project very professional. When I built my Maximite some years back I never thought it would come to this and with the 470 maybe on the horizon who knows?
Thanks to all.
Paul.
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
Zonker

Guru

Joined: 18/08/2012
Location: United States
Posts: 767
Posted: 04:19pm 29 Jun 2015
Copy link to clipboard 
Print this post

Evening Gent's...

Just got back to the house...

2015-06-30_021427_2-4_inch_volt_meter_demo.zip

The way I did it, was to keep the button sensing in the main "DO" loop going as fast as it can. When a touch is detected, you must loop waiting for the "no finger" response... That's where I turn the button a different color... Anyway, I guess there are several ways to get the job done... The demo was just to show the display doing something useful...

 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1989
Posted: 06:43pm 29 Jun 2015
Copy link to clipboard 
Print this post

Thanks Zonker, I went with Gizmo's code and it works well.
Thanks all
Paul.
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025