Native Support for ON/OFF/ON Switches
- BradyBrother100
- Posts: 54
- Joined: Tue Oct 13, 2020 4:21 pm
- Location: United States MDT
Re: Native Support for ON/OFF/ON Switches
Yeah, it's more of a convenience thing than anything.
Re: Native Support for ON/OFF/ON Switches
Hi folks,
i need some help with my ON-OFF-ON Switch.
It is working ok, but i don`t get a perfect start condition.
everytime i let the program run, the switch in xplane is not at the correct position.
here is my code
What i`m trying to say is, if the position of the switch is actually in the down position, and i start the program it appears in the up position in xplane and vice versa.
Since i`m new to lua i might have forgotten something.
I probably have to get the position first, but i don`t really know how.
By the way, it`s the FF A320 V1.1.16
Maybe someone can help me
Karl
i need some help with my ON-OFF-ON Switch.
It is working ok, but i don`t get a perfect start condition.
everytime i let the program run, the switch in xplane is not at the correct position.
here is my code
Code: Select all
function landl0_callback(position)
pos_down=position
checkMidPosition()
xpl_command("a320/Overhead/LightLandL_switch+")
end
hw_switch_add("ARDUINO_MEGA2560_A_D22", landl0_callback)
function landl2_callback(position)
pos_up=position
checkMidPosition()
xpl_command("a320/Overhead/LightLandL_switch+")
end
hw_switch_add("ARDUINO_MEGA2560_A_D23", landl2_callback)
function checkMidPosition()
if pos_up==0 and pos_down==0 then pos_mid=1
xpl_command("a320/Overhead/LightLandL_switch-")
end
end
Since i`m new to lua i might have forgotten something.
I probably have to get the position first, but i don`t really know how.
By the way, it`s the FF A320 V1.1.16
Maybe someone can help me
Karl
- Keith Baxter
- Posts: 4685
- Joined: Wed Dec 20, 2017 11:00 am
- Location: Botswana
Re: Native Support for ON/OFF/ON Switches
Hi,
Use @Ralph code. You will find it in the hardware library.
Keith
Use @Ralph code. You will find it in the hardware library.
Code: Select all
function switch_state()
if not hw_input_read(input_1) and hw_input_read(input_2) then
print"Position 1"
-- Do your stuff here for position 1, be sure to remove the print(s)
elseif hw_input_read(input_1) and hw_input_read(input_2) then
print"Position 2"
-- Do your stuff here for position 2, be sure to remove the print(s)
elseif hw_input_read(input_1) and not hw_input_read(input_2) then
-- Do your stuff here for position 3, be sure to remove the print(s)
print"Position 3"
end
end
input_1 = hw_input_add("Switch connection 1", function(state)
switch_state() -- switch_state is called when the state of this pin changes
end)
input_2 = hw_input_add("Switch connection 2", function(state)
switch_state() -- switch_state is called when the state of this pin changes
end)
-- We add a timer for redundancy
timer_start(nil, 500, function()
switch_state()
end)
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
Re: Native Support for ON/OFF/ON Switches
Thank you Keith,
i`ll try this.
I might get back to you if I`m stuck.
i`ll try this.
I might get back to you if I`m stuck.
- Keith Baxter
- Posts: 4685
- Joined: Wed Dec 20, 2017 11:00 am
- Location: Botswana
Re: Native Support for ON/OFF/ON Switches
Hi,
No problems. This is an example of a nav switch.
Code: Select all
nav_source=0
xpl_dataref_subscribe("laminar/B738/toggle_switch/vhf_nav_source","FLOAT",function(nav)
nav_source=nav
end)
function nav_source_switch()
if not hw_input_read(nav_source_1) and hw_input_read(nav_source_2) then
xpl_command("laminar/B738/toggle_switch/vhf_nav_source_lft")
elseif hw_input_read(nav_source_1) and hw_input_read(nav_source_2) then
if nav_source<0 then
xpl_command("laminar/B738/toggle_switch/vhf_nav_source_rgt")
elseif nav_source>0 then
xpl_command("laminar/B738/toggle_switch/vhf_nav_source_lft")
end
elseif hw_input_read(nav_source_1) and not hw_input_read(nav_source_2) then
xpl_command("laminar/B738/toggle_switch/vhf_nav_source_rgt")
end
end
nav_source_1=hw_input_add("ARDUINO_MEGA2560_A_D3", function(state)
nav_source_switch()
end)
nav_source_2 = hw_input_add("ARDUINO_MEGA2560_A_D4", function(state)
nav_source_switch()
end)
-- We add a timer for redundancy
timer_start(nil, 500, function()
nav_source_switch()
end)
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