Use a switch by change not on/off status.


Closed Thread
Results 1 to 17 of 17

Hybrid View

  1. #1
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,132


    Did you find this post helpful? Yes | No

    Default Re: Use a switch by change not on/off status.

    Try this. I have not tested though, but is based on Roberts idea to work as you requested. Roberts idea will toggle the output everytime the switch will change state. Not on 0->1 only.

    Code:
    SwitchIn VAR PortB.0
    OldState VAR BIT
    SwitchState VAR BIT
    
    OldState = SwitchIn
    SwitchState = 0
    
    Main:
      IF SwitchIn not = OldState THEN
        IF SwitchIn THEN
          SwitchState = SwitchState ^ %1  ' Switch has been toggled
        ENDIF
      ENDIF
    OldState = SwitchIn
    GOTO Main
    Ioannis

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


    Did you find this post helpful? Yes | No

    Default Re: Use a switch by change not on/off status.

    You can tweak a PAUSE 50 before GOTO as simple debounce.

    Robert

  3. #3
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,132


    Did you find this post helpful? Yes | No

    Default Re: Use a switch by change not on/off status.

    I think debounce is not necessary since he wants to see the edge from 0->1 and toggle the output. Then do nothing with 1->0 until a new 0->1 edge comes.

    Ioannis

  4. #4
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,159


    Did you find this post helpful? Yes | No

    Default Re: Use a switch by change not on/off status.

    I know, I was just suggesting minimal debounce as he requested.
    All with sufficient code to avoid bouncing.
    Robert

Similar Threads

  1. Toggle switch (latching switch) state
    By craigwb in forum General
    Replies: 4
    Last Post: - 6th November 2011, 14:18
  2. Switch sensor vs. switch PIC pin
    By fratello in forum Schematics
    Replies: 10
    Last Post: - 4th August 2011, 11:17
  3. Interrupt status?
    By circuitpro in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 28th February 2011, 01:27
  4. Replies: 6
    Last Post: - 9th January 2011, 15:26

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