toggle switches and buttons-- need little help


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2012
    Location
    Philadelphia Metro, PA
    Posts
    5

    Default toggle switches and buttons-- need little help

    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:
    Code:
    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

  2. #2
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default Re: toggle switches and buttons-- need little help

    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

  3. #3
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    427


    Did you find this post helpful? Yes | No

    Default Re: toggle switches and buttons-- need little help

    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.


    Code:
    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...
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

Similar Threads

  1. 12F683 + buttons
    By sincity337 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 14th October 2010, 19:53
  2. Buttons
    By WarPony in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 16th May 2008, 01:47
  3. 6 Buttons
    By Johansch in forum General
    Replies: 3
    Last Post: - 4th July 2007, 15:21
  4. toggle command w/ multiple switches
    By earltyso in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 15th February 2007, 17:47
  5. Latched buttons
    By peu in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 25th January 2006, 00:22

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts