Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 19:08 17 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 : Help using touch screen

Author Message
Benzol
Regular Member

Joined: 07/01/2015
Location: Australia
Posts: 64
Posted: 04:15pm 10 Feb 2016
Copy link to clipboard 
Print this post

Hi everyone
I am having trouble working out how to use the LCD touch screen. I would like to turn on a relay for lighting when i touch a circle on the screen. There will be four circles for 4 different lighting circuits. Then turn off the relay(s) when the circle is touched again.
I just can't figure out the code.
Can anybody out there point me in the right direction please.
Regards db
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9595
Posted: 04:33pm 10 Feb 2016
Copy link to clipboard 
Print this post

Hi-de-hi.

As far as I know, circular buttons are not supported.
Square or rectangular ones are, but circular ones are not.

You could use a radio-button box to select the lamp you wanted, and as each radio-button was selected, it would automatically turn the others off. Only one could be on at any one time though, and that might not suit.

You can make the radio-buttons any size you like though.

Our Cfunction gurus might be able to write something to generate circular buttons.

EDIT: Oh, BTW - Standard MM2 or MM+?Edited by Grogster 2016-02-12
Smoke makes things work. When the smoke gets out, it stops!
 
Benzol
Regular Member

Joined: 07/01/2015
Location: Australia
Posts: 64
Posted: 04:45pm 10 Feb 2016
Copy link to clipboard 
Print this post

Hi Grogster
I'm using the standard micromite II V5.1 as per the backpack in Silicon Chip. Drawing the circles is easy enough, I figured it would 'look' for the X,Y of the circle to go high on touch to trigger a DOUT high.Maybe I'm just on the wrong track altogether.
cheers.
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9595
Posted: 05:35pm 10 Feb 2016
Copy link to clipboard 
Print this post

Hi-de-hi.

Yes, that makes a difference. I thought you meant MM+. I think you can just define an area on the screen where your circles are, and if you touch that area(which will also have the circle on it), then that will trigger the touch interrupt.

I will see if I can hook up a screen to a MM2 later on and have a play - I have only really tinkered with the MM+ touch side of things thus far.

Others will no doubt chime in with ideas, code snippets and examples I am sure.
Smoke makes things work. When the smoke gets out, it stops!
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2934
Posted: 10:33pm 10 Feb 2016
Copy link to clipboard 
Print this post

Grogs,

Can you not 'frame' radio buttons in MMBasic?
If so, then have four 'frames' and each radio button will work independently of all the others!

Just an idea . . .

WW
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9595
Posted: 03:31am 11 Feb 2016
Copy link to clipboard 
Print this post

Just an idea, and a very good one!
Yes, I expect that should work.
However, that is MM+ GUI - I don't think radio-buttons and boxes are supported in the 28-pinner are they?
Smoke makes things work. When the smoke gets out, it stops!
 
disco4now

Guru

Joined: 18/12/2014
Location: Australia
Posts: 1000
Posted: 11:56am 11 Feb 2016
Copy link to clipboard 
Print this post

Geoff's ParkingAssist program shows some good methods of doing buttons/input etc on the 28 pin LCD backpack. Just comment out the lines for the hardware and you can get a good idea how it runs. There are some nice little routines that would be a good starting point for anything you want to do.


Geoff's ParkingAssist program

Thread where Geoff upload it

Regards
Gerry
Latest F4 Latest H7 FotS
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6271
Posted: 01:16pm 11 Feb 2016
Copy link to clipboard 
Print this post

Simple demo:
' OPTION LCDPANEL controller, orientation, D/C pin, reset pin [,CS pin]
' OPTION LCDPANEL ILI9341, RL, 4,5,6
' OPTION TOUCH T_CS pin, T_IRQ pin
' OPTION TOUCH 7,2
' GUI CALIBRATE
OPTION EXPLICIT
OPTION CLOCKTRIM -4
cls
SETPIN 26,DOUT ' display brightness
PIN(26)=1
COLOUR RGB(GREEN), RGB(BLACK)
FONT 1, 3
circle 50,50,40 'button1
circle 50,150,40 'button2
circle 150,50,40 'button3
circle 150,150,40 'button4

main:
DO
'
IF TOUCH(X) <> -1 THEN tapped
LOOP
END

SUB tapped
LOCAL tx,ty
tx=TOUCH(X)
ty=TOUCH(Y)
if ty > 0 and tx > 0 then
if tx > 10 and tx < 90 and ty > 10 and ty < 90 then
print "Button1"
endif
if tx > 110 and tx < 190 and ty > 10 and ty < 90 then
print "Button2"
endif
if tx > 10 and tx < 90 and ty > 110 and ty < 190 then
print "Button3"
endif
if tx > 110 and tx < 190 and ty > 110 and ty < 190 then
print "Button4"
endif

endif
pause 200
END SUB


Not sure if the display brightness pin is correct for your hardware.

The conditional statements could easily be improved depending on your layout.

Jim
VK7JH
MMedit
 
Benzol
Regular Member

Joined: 07/01/2015
Location: Australia
Posts: 64
Posted: 02:00pm 11 Feb 2016
Copy link to clipboard 
Print this post

Hi Jim. that's awesome, I never ceased to be amazed by the expertise on this site. I'm at work and can't try it until I get home. Will let you know.
Regards db
 
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