PDA

View Full Version : toggle switches and buttons-- need little help



electromark
- 25th October 2012, 00:40
Thanks in advance to all who help.

Im working on a project where there has to be provisions for the following:

2 sets of momentary pushbuttons:

Set1 ON/OFF (turns an LED on / off)
Set2 ON/OFF (turns an LED on / off)

and 2 toggle buttons:

TOGGLE1 (turns an LED on / off)
TOGGLE2 (turns an LED on / off)

The momentary buttons work like a champ. Im running in to trouble with the toggles. When they activate, the program freezes until they are turned off. I need to, when either or both of the toggle switches are on to continue on with the program- i.e. reading the momentary buttons, ect.
Any help would be appreciated.
part of my code example is below:


do

' PLOW FUNCTION
COUNTER1 = 0 ' Reset count
DO WHILE (PLOWUP = 0) OR (PLOWDOWN = 0) ' Loop while button pressed
PAUSE 1 ' Give the loop a 1mS execution time
counter1 = counter1 + 1 ' Count a loop (1mS)
IF counter1 = threshold1 THEN ' Reached threshold time?
PLOWOUT = PLOWUP

ENDIF

LOOP

' DUMP FUNCTION

COUNTER2 = 0
DO WHILE (DUMPDOWN = 0) OR (DUMPUP = 0) ' Loop while button pressed
PAUSE 1 ' Give the loop a 1mS execution time
counter2 = counter2 + 1 ' Count a loop (1mS)
IF counter2 = threshold2 THEN ' Reached threshold time?
DUMPOUT = DUMPDOWN
ENDIF

LOOP


;switch code in here??


LOOP

Demon
- 25th October 2012, 03:58
I see only a comment for your switch code, and the code for what seems like 4 buttons (Plow up/down, Dump up/down).

Robert

Heckler
- 25th October 2012, 22:35
If you want your code to just check the position of the switches, set the corresponding LED's and then move on to something else (like checking if a button is pressed then something like this should work. You will just need to take into account how often the program will make it to this part of the code to check switch postion.




If switch1 = 1 then switch1LED=1 else switch1LED=0
If switch2 = 1 then switch2LED=1 else switch2LED=0

'now continue on to the rest of the program...


hope this helps...