General area when it fits no where else

Moderator: Mmiscool

User avatar
By Luc Volders
#66112 From lightyears ago.
We always used to use the NOT function.
so toggle = ! toggle

Code: Select alltoggle = 1
button "switch", [switch]
wait

[switch]
toggle = ! toggle
io(po,d2,(abs(toggle))
wait


Toggle wil avry betweem 0 and -1
By using the ABS value of toggle you will be able to set directly an I/O port

Same result as jimg only a bit easier to remember (for me)

Luc
User avatar
By Electroguard
#66113 If you use an led pin as your flag you can have visual feedback of the state of your flag.
Remember that button interrupt only needs to do something on either the press or release, which is checked in [PRESSED].


Code: Select allledpin = 1     'Use ledpin as your flag variable
buttonpin = 0  'Uses gpio00 flashing button by default, change to suit (needs pullup resistor).
interrupt buttonpin, [PRESSED]
wait

[PRESSED]
if io(laststat,buttonpin) = 0 then gosub [TOGGLE]  'else do nothing
wait

[TOGGLE]
if io(laststat,ledpin) = 1 then io(po,ledpin,0) else io(po,ledpin,1)
return