Benzol Regular Member
 Joined: 07/01/2015 Location: AustraliaPosts: 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: GermanyPosts: 1769 |
| 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 ‚My name is Ozymandias, king of kings Look on my works, ye Mighty, and despair!‘ Nothing beside remains. Round the decay Of that colossal wreck, boundless and bare The lone and ... |
twofingers
 Guru
 Joined: 02/06/2014 Location: GermanyPosts: 1769 |
| 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 ‚My name is Ozymandias, king of kings Look on my works, ye Mighty, and despair!‘ Nothing beside remains. Round the decay Of that colossal wreck, boundless and bare The lone and ... |