Multiple functions by a single switch


Today 20:28
Forum: PICKit Plus
Starter: evan
Views: 0
Replies: 7
Today 13:26
Forum: Proton Plus Compiler v3
Starter: gdesantis
Views: 0
Replies: 2
Today 11:23
Forum: The Lounge
Starter: Les
Views: 0
Replies: 12
+ Reply to Thread
Page 1 of 4 123 ... LastLast
Results 1 to 10 of 34

Thread: Multiple functions by a single switch34 days old

  1. #1
    Junior Member amod's Avatar
    Join Date
    Mar 2018
    Posts
    67
    Thumbs Up
    Received: 43
    Given: 4
    Total Downloaded
    5.95 MB

    0 Not allowed!

    Default Multiple functions by a single switch

    Hi,
    How can I use multiple function by a single switch.I want to use 4 functions by a single switch.

  2. #2
    Fanatical Contributor Tim's Avatar
    Join Date
    Jan 2003
    Posts
    7,564
    Thumbs Up
    Received: 65
    Given: 91
    Total Downloaded
    895.24 MB

    0 Not allowed!

    Default Re: Multiple functions by a single switch

    Do you want 4 buttons on one pic pin or 4 functions of 1 button?
    Tim

  3. #3
    Junior Member amod's Avatar
    Join Date
    Mar 2018
    Posts
    67
    Thumbs Up
    Received: 43
    Given: 4
    Total Downloaded
    5.95 MB

    0 Not allowed!

    Default Re: Multiple functions by a single switch

    4 functions by a single switch.

  4. #4
    Prolific Poster joesaliba's Avatar
    Join Date
    Sep 2004
    Posts
    2,374
    Thumbs Up
    Received: 86
    Given: 23
    Total Downloaded
    4.04 GB

    0 Not allowed!

    Default Re: Multiple functions by a single switch

    The following code will go through five different function upon your selection. This was a quick code just to let you think about it. NOT TESTED but should work.

    Code:
    Dim Sele As Byte = 0
    Dim Time As Word = 0
    
    '----------------------------------------------------------------------------------------
    
    Main:
    
    If But = 0 Then                 ' If push is pressed then
        DelayMS 100                 ' some debounce delay
        Inc Sele                    ' increase Sele
        Time = 0                    ' clear Time
        If Sele = 5 Then Sele = 0   ' reset counter Sele to 0 if more than 4 
    EndIf
    
    
    DelayMS 1                       ' Delay of 1ms to determine time
    Inc Time                        ' Increase Time
    
    If Time < 500 Then GoTo Main    ' If Time is smaller 500ms then goto Main
    
    On Sele GoToL Main , Label_1 , Label_2 , Label_3 , Label_4
    
    GoTo Main                       ' Goto Main just in case something weird happened
    
    '----------------------------------------------------------------------------------------
    
    Label_1:
    
    ' This label code goes here
         
    GoTo Main
    
    '----------------------------------------------------------------------------------------
    
    Label_2:
    
    ' This label code goes here
         
    GoTo Main
    
    '----------------------------------------------------------------------------------------
    
    Label_3:
    
    ' This label code goes here
         
    GoTo Main
    
    '----------------------------------------------------------------------------------------
    
    Label_4:
    
    ' This label code goes here
         
    GoTo Main
    
    '----------------------------------------------------------------------------------------
    After selecting the desired switch command, after 500ms it will jump to the label the selection was done.

    Sele = 0 will do the Main routine
    Sele = 1 will jump to Label_1
    Sele = 2 will jump to Label_2
    Sele = 3 will jump to Label_3
    Sele = 4 will jump to Label_4

    If you want to minimise the time the routine jumps to the label change the value of: -

    Code:
    If Time < 500 Then GoTo Main    ' If Time is smaller 500ms then goto Main
    to what you desire. I.e.: - 400 will jump after 400ms you release the button etc. 1000 will jump to the label after 1 second etc
    Regards

    Joseph

  5. #5
    Member craig's Avatar
    Join Date
    Dec 2010
    Posts
    134
    Thumbs Up
    Received: 7
    Given: 0
    Total Downloaded
    611.61 MB

    0 Not allowed!

    Default Re: Multiple functions by a single switch

    Hello Amod

    You can only read a 0 or a 1 from a Single Pole switch which can only give Two Functions.
    Otherwise you could use Four Single Pole Switches
    and connect them to a single pin under ADC and then put resistors between the four switches to give different Readings (Voltages) on the ADC
    When each switch is pushed, It will give a different Voltage(ADC_Reading).
    Then put a Select - Case Loop In to Read the different values and assign each to it's own Gosub routine to get your Four different functions.
    Regards

    Craig

  6. #6
    Junior Member amod's Avatar
    Join Date
    Mar 2018
    Posts
    67
    Thumbs Up
    Received: 43
    Given: 4
    Total Downloaded
    5.95 MB

    0 Not allowed!

    Default Re: Multiple functions by a single switch


  7. #7
    Member craig's Avatar
    Join Date
    Dec 2010
    Posts
    134
    Thumbs Up
    Received: 7
    Given: 0
    Total Downloaded
    611.61 MB

    0 Not allowed!

    Default Re: Multiple functions by a single switch

    Amod

    Your Screenshot is a bit small to see clearly. The only thing I can think of if you wan't to use a Single button to do
    Four different functions is to have a counter attached and lets say one press does task 1, Second Press does task 2 and so on.
    You must de-bounce the switch and have a small delay to stop overlapping.

    Regards
    Craig

  8. #8
    Prolific Poster charliecoultas's Avatar
    Join Date
    Sep 2010
    Posts
    1,212
    Thumbs Up
    Received: 73
    Given: 37
    Total Downloaded
    2.84 GB

    0 Not allowed!

    Default Re: Multiple functions by a single switch

    I think what he wants is like Joseph suggested: hold the switch down for a short time is one function, a bit longer for the second and so on.
    I seem to remember Les describing a single button that you could tap morse code into (a long long time ago) for a security system.

    There is a bell push that rings the bell if held down, or opens the door after a short series of sharp stabs.

    Charlie

  9. #9
    Junior Member amod's Avatar
    Join Date
    Mar 2018
    Posts
    67
    Thumbs Up
    Received: 43
    Given: 4
    Total Downloaded
    5.95 MB

    0 Not allowed!

    Default Re: Multiple functions by a single switch

    Press 1
    Function 1
    Press 2
    Function 2
    Press 3
    Function 3
    Press 4
    Function 4. and so on..

    Press 1
    Decimal point
    Press 2
    Calibration factor
    Press 3
    Mode
    Press 4
    Calibration
    Press 5
    Multiplying factor
    End

    I will upload a video tomorrow
    Last edited by amod; 9th November 2018 at 19:13.

  10. #10
    Prolific Poster joesaliba's Avatar
    Join Date
    Sep 2004
    Posts
    2,374
    Thumbs Up
    Received: 86
    Given: 23
    Total Downloaded
    4.04 GB

    0 Not allowed!

    Default Re: Multiple functions by a single switch

  11. So my example code works for you. I used that method long time ago and it works, maybe it needs some tweaks but it works. If you have an LCD attached it is even better because you can see at what stage your push sequence have arrived.

    Not only it works with a push button. Long time ago I have managed to use a singe R/C channel with a spring loaded switch to activate 3 separate items depends on how many times I toggled the switch.
    Regards

    Joseph

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. TCK106AF, TCK107AF and TCK108AF single-chip load switch ICs
    By normnet in forum New devices and techniques
    Replies: 0
    Last Post: 31st March 2016, 23:19
  2. Multiple button on a single ADC port.
    By wirecut in forum Proton Plus Compiler v3
    Replies: 10
    Last Post: 14th July 2014, 19:52
  3. New ADG5419 single-pole/double-throw (SPDT) switch
    By normnet in forum New devices and techniques
    Replies: 0
    Last Post: 5th April 2014, 23:09
  4. Replies: 0
    Last Post: 5th April 2014, 23:09
  5. Multiple PIC's driven from a single reset
    By knight in forum The Lounge
    Replies: 8
    Last Post: 24th October 2010, 08:56

Posting Permissions

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