Toggle Switch Off Position
- BradyBrother100
- Posts: 54
- Joined: Tue Oct 13, 2020 4:21 pm
- Location: United States MDT
Re: Toggle Switch Off Position
Hi! I got my on/off(on) switch and tried @Sling code. It still didn't detect anything in the off position.
D22 and D23 both have connection wires and D24 is my dummy port.Re: Toggle Switch Off Position
I see the problem. You will have to use one of the other alternatives. I’d suggest adding two 1 way switches and in code when both are off (switch in central position) do whatever action you want for that central position.
When a 1 way switch is added it automatically assumes that if the input is not active then it must mean it’s set to off. You can use the off state to mean whatever you want.
Let us know if you need a code example.
When a 1 way switch is added it automatically assumes that if the input is not active then it must mean it’s set to off. You can use the off state to mean whatever you want.
Let us know if you need a code example.
Air Manager panels at https://www.experimentalsimavionics.com
Youtube Channel https://www.youtube.com/channel/UC8ZqXX ... kfZMq5BKig
Air Manager API Tutorial Video Series https://youtube.com/playlist?list=PLNr0 ... baT4gJKg5D
Youtube Channel https://www.youtube.com/channel/UC8ZqXX ... kfZMq5BKig
Air Manager API Tutorial Video Series https://youtube.com/playlist?list=PLNr0 ... baT4gJKg5D
- BradyBrother100
- Posts: 54
- Joined: Tue Oct 13, 2020 4:21 pm
- Location: United States MDT
Re: Toggle Switch Off Position
Hi! I used @Ralph code and that seems to be the way to go.
Code: Select all
function input_change(state)
if state == false then
print("pos2")
else print ("pos1")
end
end
function input_change2(state)
if state == false then
print ("pos0")
else print ("pos1")
end
end
-- Create a new input
hw_input_add("My input", input_change)
hw_input_add("My input2", input_change2)
Re: Toggle Switch Off Position
Yes that’s almost exactly the same but using 2 digital input’s rather than 2 one way switches. I know it works with the switch type you are using but be careful with the logic as pos1 is actually only achieved if both inputs are open. It would be cleaner to have the pos1 action code in one place rather than two.
Glad you got it sorted
Glad you got it sorted
Air Manager panels at https://www.experimentalsimavionics.com
Youtube Channel https://www.youtube.com/channel/UC8ZqXX ... kfZMq5BKig
Air Manager API Tutorial Video Series https://youtube.com/playlist?list=PLNr0 ... baT4gJKg5D
Youtube Channel https://www.youtube.com/channel/UC8ZqXX ... kfZMq5BKig
Air Manager API Tutorial Video Series https://youtube.com/playlist?list=PLNr0 ... baT4gJKg5D
- BradyBrother100
- Posts: 54
- Joined: Tue Oct 13, 2020 4:21 pm
- Location: United States MDT
Re: Toggle Switch Off Position
Hi! I got 12 On/Off/On switches and the code probably could be more simple but, I got the Off position to be registered! (Kind of)
The digital inputs are to detect when there is no signal coming from both input pins and the switch is to detect when the switch is in the on positions.
The digital inputs are to detect when there is no signal coming from both input pins and the switch is to detect when the switch is in the on positions.
Code: Select all
function Lpack(pos)
if pos == 0 then
xpl_dataref_write("laminar/B738/air/l_pack_pos", "FLOAT", 2)
print("pos2")
else
xpl_dataref_write("laminar/B738/air/l_pack_pos", "FLOAT", 0)
print("pos0")
end
end
function Lpack1(state)
if state == true then
xpl_dataref_write("laminar/B738/air/l_pack_pos", "FLOAT", 1)
print("pos1")
end
end
function Lpack2(state)
if state == true then
xpl_dataref_write("laminar/B738/air/l_pack_pos", "FLOAT", 1)
print("pos1")
end
end
hw_switch_add("Lpack", 2, Lpack)
hw_input_add("Lpack1", Lpack1)
hw_input_add("Lpack2", Lpack2)