Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 12:12 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 : LCD touch screen and toggling relays

Author Message
Benzol
Regular Member

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

Hi all
I am trying to toggles relays off and on using the LCD screen. I can get them to turn on but not off. I figure I need to read the current state of the output pins and reverse it using the subroutine but everything I try won't work. I would appreciate some help.
Many thanks to TassieJim for getting me this far.
Regards

' OPTION LCDPANEL controller, orientation, D/C pin, reset pin [,CS pin]
' OPTION LCDPANEL ILI9341, L, 2,23,6
' OPTION TOUCH T_CS pin, T_IRQ pin
' OPTION TOUCH 7,15
' GUI CALIBRATE
OPTION EXPLICIT
cls
SETPIN 26,DOUT ' display brightness

SETPIN 4, DOUT 'Pool lights relay
SETPIN 5, DOUT 'Gate light relay
SETPIN 18, DOUT 'Bins light relay
SETPIN 24, DOUT 'Front lights relay

PIN(26)=1
COLOUR RGB(GREEN), RGB(BLACK)
FONT 1, 3

'Draw Circles
circle 85, 60, 45, 3, ,rgb(green)
circle 235, 60, 45, 3, ,rgb(green)
circle 85, 180, 45, 3, ,rgb(green)
circle 235, 180, 45, 3, ,rgb(green)

'Insert Text
text 85, 60, "BINS", CM, , 2, RGB(White)
text 235, 60, "POOL", CM, ,2, RGB(White)
text 85, 180, "GATE", CM, ,2, RGB(White)
text 235, 180, "FRONT", CM, ,2, RGB(White)

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 > 40 and tx < 130 and ty > 15 and ty < 105 then
pin(18)=1
endif
if tx > 190 and tx < 280 and ty > 15 and ty < 105 then
pin(4)=1
endif
if tx > 40 and tx < 130 and ty > 135 and ty < 225 then
pin(5)=1
endif
if tx > 190 and tx < 280 and ty > 135 and ty < 225 then
pin(24)=1
endif

endif
pause 200
END SUB

 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1579
Posted: 05:04pm 14 Feb 2016
Copy link to clipboard 
Print this post

I would try this (yet untested!):

' OPTION LCDPANEL controller, orientation, D/C pin, reset pin [,CS pin]
' OPTION LCDPANEL ILI9341, L, 2,23,6
' OPTION TOUCH T_CS pin, T_IRQ pin
' OPTION TOUCH 7,15
' GUI CALIBRATE
OPTION EXPLICIT
cls

const ON =1
const OFF=0

Dim integer pin_Pool =4, sw_Pool =OFF ' sw = switch status
Dim integer pin_Gate =5, sw_Gate =OFF
Dim integer pin_Bins =18, sw_Bins =OFF
Dim integer pin_Front =24, sw_Front=OFF
Dim integer pin_LCD_Br=26

SETPIN pin_LCD_Br,DOUT ' display brightness

SETPIN pin_Pool, DOUT 'Pool lights relay
SETPIN pin_Gate, DOUT 'Gate light relay
SETPIN pin_Bins, DOUT 'Bins light relay
SETPIN pin_Front,DOUT 'Front lights relay

PIN(26)=ON
PIN(pin_Pool) =sw_Pool
PIN(pin_Gate) =sw_Gate
PIN(pin_Bins) =sw_Bins
PIN(pin_Front)=sw_Front

COLOUR RGB(GREEN), RGB(BLACK)
FONT 1, 3

'Draw Circles
circle 85, 60, 45, 3, ,rgb(green)
circle 235, 60, 45, 3, ,rgb(green)
circle 85, 180, 45, 3, ,rgb(green)
circle 235, 180, 45, 3, ,rgb(green)

'Insert Text
text 85, 60, "BINS", CM, , 2, RGB(White)
text 235, 60, "POOL", CM, ,2, RGB(White)
text 85, 180, "GATE", CM, ,2, RGB(White)
text 235, 180, "FRONT", CM, ,2, RGB(White)

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 > 40 and tx < 130 and ty > 15 and ty < 105 then
sw_Bins=not(sw_Bins) ' toggle switch
PIN(pin_Bins)=sw_Bins
endif
if tx > 190 and tx < 280 and ty > 15 and ty < 105 then
sw_Pool=not(sw_Pool)
pin(pin_Pool)=sw_Pool
endif
if tx > 40 and tx < 130 and ty > 135 and ty < 225 then
sw_Gate=not(sw_Gate)
pin(pin_Gate)=sw_Gate
endif
if tx > 190 and tx < 280 and ty > 135 and ty < 225 then
sw_Front=not(sw_Front)
pin(pin_Front)=sw_Front
endif

endif
pause 200
END SUB
Edited by twofingers 2016-02-16
causality ≠ correlation ≠ coincidence
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9594
Posted: 05:07pm 14 Feb 2016
Copy link to clipboard 
Print this post

Use flags in your touch routine if you want on/off type operation.

Example:


SUB tapped
LOCAL tx,ty
tx=TOUCH(X)
ty=TOUCH(Y)
if ty > 0 and tx > 0 then
if tx > 40 and tx < 130 and ty > 15 and ty < 105 then
if FLAG1=1 then
pin(18)=0
FLAG1=0
else
pin(18)=1
FLAG1=1
Endif
endif
if tx > 190 and tx < 280 and ty > 15 and ty < 105 then
if FLAG2=1 then
pin(4)=0
FLAG2=0
else
pin(4)=1
FLAG2=1
Endif
endif
if tx > 40 and tx < 130 and ty > 135 and ty < 225 then
if FLAG3=1 then
pin(5)=0
FLAG3=0
else
pin(5)=1
FLAG3=1
Endif
endif
if tx > 190 and tx < 280 and ty > 135 and ty < 225 then
if FLAG4=1 then
pin(24)=0
FLAG4=0
else
pin(24)=1
FLAG4=1
Endif
endif

endif
pause 200
END SUB


That SHOULD work, but I have not tested it.
Smoke makes things work. When the smoke gets out, it stops!
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1579
Posted: 05:21pm 14 Feb 2016
Copy link to clipboard 
Print this post

many ways lead to rome ...

Maybe you should add some code like this (untested):


dim integer Status_Color(1)=(rgb(green),rgb(red))
...
...

if tx > 40 and tx < 130 and ty > 15 and ty < 105 then
sw_Bins=not(sw_Bins) ' toggle switch
PIN(pin_Bins)=sw_Bins
circle 85, 60, 45, 3, ,Status_Color(sw_Bins)
endif

...
...
Edited by twofingers 2016-02-16
causality ≠ correlation ≠ coincidence
 
Benzol
Regular Member

Joined: 07/01/2015
Location: Australia
Posts: 64
Posted: 05:35pm 14 Feb 2016
Copy link to clipboard 
Print this post

Thank you Twofingers and Grogster. A couple of very helpful options there. it is amazing that there can be so many different interpretations for the same result.
I will let you know of the outcome.
Cheers.
 
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