Toggle Switch Off Position

Support for Arduino in combination with Air Manager and Air Player

Moderators: russ, Ralph

Message
Author
User avatar
BradyBrother100
Posts: 54
Joined: Tue Oct 13, 2020 4:21 pm
Location: United States MDT

Toggle Switch Off Position

#1 Post by BradyBrother100 »

Hi! Before buying a On/Off/On switch, I want to know if Air Manager can detect if the switch is Off. Can it or can it only detect if the switch is completing the circuit?





Thanks!
Brady

User avatar
Keith Baxter
Posts: 4684
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: Toggle Switch Off Position

#2 Post by Keith Baxter »

Hi Brady,

The short answer YES.

This will help you with all types of hardware. Note the different switch types. Whilst there is not a o/f/o switch diagram the principle is the same as two single switches.

http://siminnovations.com/wiki/index.ph ... n_examples

Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

User avatar
Sling
Posts: 5237
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: Toggle Switch Off Position

#3 Post by Sling »

Brady,

As a minimum all systems including Air Manager that need to accept an electrical switch input need to be able to determine the difference between at least 2 states. This doesn’t necessarily mean you need a wire from 2 positions of that switch because you can represent the 2 states with a single wired connection to the micro and some form of switch common.

I can see why you may ask about a 3 position with centre off switch but It’s quite easy to implement. You have a few options depending on the type of switch and how you need it to work.

Add 2 AM buttons if the switch is a momentary action type. Each I/O line would connect to one of the switched terminals and the Arduino gnd to the switch common.

Add 2 AM switches and connect the same as for the buttons and just use the individual switch callbacks to action whatever you is want.

Lastly and probably the most conventional method would be to add a single 3 way switch in AM. This again only requires 2 Arduino I/O pins. The callback in this instance will return a position. You just use the returned position to determine what action to take.

User avatar
BradyBrother100
Posts: 54
Joined: Tue Oct 13, 2020 4:21 pm
Location: United States MDT

Re: Toggle Switch Off Position

#4 Post by BradyBrother100 »

Ok, so how would I assign each position if there are only three wires going to the Arduino?(That includes the ground connection)
https://www.amazon.com/Twidec-Rocker-To ... ast_sto_dp These are the on/off/on switches I am planning on getting.
image.png
image.png (8.27 KiB) Viewed 3393 times

User avatar
Keith Baxter
Posts: 4684
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: Toggle Switch Off Position

#5 Post by Keith Baxter »

Brady,

0= on(1) wire connected to arduino
1= off No wire connected to arduino BUT the arduino pin assigned must not be used for anything.
2= on(2) wire connected to arduino

The switch center wire is your earth.


Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

User avatar
BradyBrother100
Posts: 54
Joined: Tue Oct 13, 2020 4:21 pm
Location: United States MDT

Re: Toggle Switch Off Position

#6 Post by BradyBrother100 »

Cool! That should work!




Thanks!
Brady

User avatar
Sling
Posts: 5237
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: Toggle Switch Off Position

#7 Post by Sling »

All,

This is a bit hacky and I would prefer the option in the API to be able to be able to specify a switch position as off rather than having to allocate the I/O pin and just not use it. However you can re-use the un-connected pin if you don't like the idea of wasting a pin every time you want an off position.

Note you can specify an off for a simple 2-way switch by only setting the number of positions to 1 and AM will take care of the rest but we should really have something in the API for using an off (no connection) with a switch of any number of positions.

perhaps @Corjan , @Ralph can add to the to-do list.

The current hacky way is configured in a similar way to what follows.

hardware set as:-
3-way switch
pin pos 0 : D2
pin pos 1 : D3
pin pos 2 : D4 (leave un-connected)

button : D4

Code: Select all

function sw_callback(pos)

    print(pos)

end
hw_switch_add("test sw", 3, sw_callback)


function but_callback()

    print("button")

end
hw_button_add("test_but", but_callback)


User avatar
BradyBrother100
Posts: 54
Joined: Tue Oct 13, 2020 4:21 pm
Location: United States MDT

Re: Toggle Switch Off Position

#8 Post by BradyBrother100 »

Hi! Yah, that would be nice if AM could detect if there was no signal coming from a switch. https://www.cockpitsimparts.co.uk/switc ... n-mon.html This is the switch I am probably going to get. I'll try your code once I get it.

Thanks!
Brady

User avatar
Sling
Posts: 5237
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: Toggle Switch Off Position

#9 Post by Sling »

Not a case of AM detecting no signal as it can do this already in the same way as any micro controller can. What we need is a means to tell AM when one of the defined number of switch ways is not needed.

Let us know how you go once your switch turns up.

User avatar
Ralph
Posts: 7917
Joined: Tue Oct 27, 2015 7:02 pm
Location: De Steeg
Contact:

Re: Toggle Switch Off Position

#10 Post by Ralph »

An alternative way is to do it with digital_input and then combine the two states.

Post Reply