View Full Version : How to use BUTTON command right?
Sharky
- 13th December 2005, 13:15
Hi,
I'm trying to switch a relay on and off with the help of BUTTON and TOGGLE command.
It's working but not the way I want it to work, because when I press the button
the relay is switching on and off like a old fasion doorbell.
How do I make a "while button is pressed just toggle once and then wait to next
time the button is pressed" before switching again?
Gert
Acetronics2
- 13th December 2005, 13:25
Hi, Gert
And what about showing us some of your lines ????
Alain
Tissy
- 13th December 2005, 23:16
Hi Gert,
I think this is what you may be after:
' ---------- [ I/O Definition ] ----------
TRISC = %00000001 ' Set PORTC (0-2 input) rest Outputs
PORTB = 0
' ---------- [ System Inputs ] ----------
Switch Var PORTC.0 ' Momentary Switch on PORTC.0
' ---------- [ System Outputs ] ----------
RedLED VAR PORTB.1 ' All LEDs connected
' between RC pins and
' ground via resistor
Main:
If Switch=1 Then ' If button is pressed:
Toggle RedLED ' Toggle the LED
loop: If Switch=1 Then Goto loop ' Wait until the button is released
Endif
Goto Main
Regards,
Steve
chuck
- 14th December 2005, 00:08
Is this wht your after try it and lets us know
it uses 1 button to turn led on/off
led1_status var bit
button1 var portb.0
led1 var portb.1
main:
if button1 = 1 then ' if the button is pressed
if led1_status = 1 then ' if its last state was 1
led1_status = 0 ' make it 0
low led1
pause 500 'debounce
else
led1_status = 1 ' the last state was a 0 so now make it a 1
high led1
pause 500 'debounce
endif
endif
chuck
chuck
- 14th December 2005, 00:33
I see that i missed the goto main of at the end
i see that Tissy replied beofre me that must have been while i went and add a coffie but at least you have got to ways of doing it now
chuck
Sharky
- 14th December 2005, 06:54
Hi,
Thanks to Tissy and Chuck for your examples.
I can conclude that you don't use the BUTTON command when you "read" a switch.
I just thought that it was possible to set up all the parameters with the BUTTON command.
But I think that your examples teach me that using IF - THEN and GOTO or WHILE - WEND gives me much better possibilities.
Gert
Powered by vBulletin® Version 4.1.7 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.