Multiple functions by a single switch

# Thread: Multiple functions by a single switch – 133 days old

1. 1

## 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. Attention
×

This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

If you can, please report issues in the forum area WebSite / Forum Issues

3. 0

## Re: Multiple functions by a single switch

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

4. Attention
×

This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

If you can, please report issues in the forum area WebSite / Forum Issues

5. 0

## Re: Multiple functions by a single switch

4 functions by a single switch.

6. Attention
×

This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

If you can, please report issues in the forum area WebSite / Forum Issues

7. 0

## 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

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

8. Attention
×

This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

If you can, please report issues in the forum area WebSite / Forum Issues

9. 0

## 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
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

10. Attention
×

This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

If you can, please report issues in the forum area WebSite / Forum Issues

11. 0

## Re: Multiple functions by a single switch

12. Attention
×

This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

If you can, please report issues in the forum area WebSite / Forum Issues

13. 0

## 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

14. Attention
×

This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

If you can, please report issues in the forum area WebSite / Forum Issues

15. 0

## 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

16. Attention
×

This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

If you can, please report issues in the forum area WebSite / Forum Issues

17. 0

## 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

18. Attention
×

This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

If you can, please report issues in the forum area WebSite / Forum Issues

19. 0

## Re: Multiple functions by a single switch

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.

20. Attention
×

This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

If you can, please report issues in the forum area WebSite / Forum Issues