AOA Indexer Project

Support for Arduino in combination with Air Manager and Air Player

Moderators: russ, Ralph

Message
Author
DH14300
Posts: 21
Joined: Mon Sep 26, 2022 6:56 pm

Re: AOA Indexer Project

#21 Post by DH14300 »

Thanks for the info Ralph! I will definitely explore that further.
Here's a couple of pics of the flight sim room for those interested:
FlightRoom1.jpg
FlightRoom2.jpg
FlightRoom3.jpg

DH14300
Posts: 21
Joined: Mon Sep 26, 2022 6:56 pm

Re: AOA Indexer Project

#22 Post by DH14300 »

Ok...after perusing the forum and Wiki, I've decided to try to incorporate a timer into my AOA indexer code whereby the tailhook position (stowed vs deployed) makes the LEDs flash or not (seems there are a number of ways to do this but, as a beginner, I was unsuccessful at finding a clear path forward). I will test this code this evening:

Code: Select all

led_AOAlow = hw_output_add("ARDUINO_NANO_A_D2", false) -- Fast, Red Chevron
led_AOAnorm = hw_output_add("ARDUINO_NANO_A_D4", false) -- On Speed, Amber Donut
led_AOAhigh = hw_output_add("ARDUINO_NANO_A_D6", false) -- Slow, Green Chevron

function new_data_fsx(AOA, HookPos)
     if HookPos >1 then
	  hw_output_set(led_AOAhigh, AOA >=11.1)  	
	  hw_output_set(led_AOAnorm, AOA >=9.75 and AOA <=11.53)
    	  hw_output_set(led_AOAlow, AOA <=10.17 and AOA >5.0)
     else
     function timer_callback(-1) --callsback infintely every 1 sec?
	  hw_output_set(led_AOAhigh, AOA >=11.1)  	
	  hw_output_set(led_AOAnorm, AOA >=9.75 and AOA <=11.53)
    	  hw_output_set(led_AOAlow, AOA <=10.17 and AOA >5.0)
     end
  end
fsx_variable_subscribe("INCIDENCE ALPHA", "Degrees", 
		       "TAILHOOK POSITION", "Percent", new_data_fsx)
timer_start(1000, 1000, timer_callback)

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

Re: AOA Indexer Project

#23 Post by Ralph »

You cannot place a timer callback function within another function. I'll make an example tomorrow.

DH14300
Posts: 21
Joined: Mon Sep 26, 2022 6:56 pm

Re: AOA Indexer Project

#24 Post by DH14300 »

OK. Considering that then...

Code: Select all

function new_data_fsx(AOA, HookPos)
     if HookPos >1 then
	  hw_output_set(led_AOAhigh, AOA >=11.1)  	
	  hw_output_set(led_AOAnorm, AOA >=9.75 and AOA <=11.53)
    	  hw_output_set(led_AOAlow, AOA <=10.17 and AOA >5.0)
     end
function timer_callback(-1) --callsback infintely every 1 sec?
     if HookPos <1 then
	  hw_output_set(led_AOAhigh, AOA >=11.1)  	
	  hw_output_set(led_AOAnorm, AOA >=9.75 and AOA <=11.53)
    	  hw_output_set(led_AOAlow, AOA <=10.17 and AOA >5.0)
     end
  end

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

Re: AOA Indexer Project

#25 Post by Ralph »

It becomes 'complicated' very quickly :) It is flashing at 250 ms right now, you can change that to something else if you want.

Code: Select all

led_AOAlow = hw_output_add("ARDUINO_NANO_A_D2", false) -- Fast, Red Chevron
led_AOAnorm = hw_output_add("ARDUINO_NANO_A_D4", false) -- On Speed, Amber Donut
led_AOAhigh = hw_output_add("ARDUINO_NANO_A_D6", false) -- Slow, Green Chevron

function new_data_fsx(AOA, HookPos, bus_volts)

    local power = bus_volts >= 10

    if HookPos > 1 and power then
        if not timer_running(timer_aoa_flash) then
            timer_aoa_flash = timer_start(nil, 250, function(count)
	        hw_output_set(led_AOAhigh, count % 2 == 0)  	
	        hw_output_set(led_AOAnorm, count % 2 == 0)
    	        hw_output_set(led_AOAlow, count % 2 == 0)
            end)
        end
    elseif HookPos < 1 and power then
        timer_stop(timer_aoa_flash)
        hw_output_set(led_AOAhigh, AOA >= 11.1)  	
        hw_output_set(led_AOAnorm, AOA >= 9.75 and AOA <= 11.53)
        hw_output_set(led_AOAlow, AOA > 5.0 and AOA <= 10.17)
    else
        timer_stop(timer_aoa_flash)
        hw_output_set(led_AOAhigh, false)  	
        hw_output_set(led_AOAnorm, false)
        hw_output_set(led_AOAlow, false)
    end

end
  
fsx_variable_subscribe("INCIDENCE ALPHA", "Degrees",
                       "TAILHOOK POSITION", "Percent", 
                       "ELECTRICAL MAIN BUS VOLTAGE", "Volts", new_data_fsx)

DH14300
Posts: 21
Joined: Mon Sep 26, 2022 6:56 pm

Re: AOA Indexer Project

#26 Post by DH14300 »

Yes, I see it certainly does! Thanks Ralph. I'll test the code this evening and continue to read up and learn here in the forums.
Dan

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

Re: AOA Indexer Project

#27 Post by Ralph »

Be careful with starting timers within a flight simulator callback function. If you don't check if it is running, then it'll spawn a new timer each time the flight sim callback function gets new data. Therefore there's a 'timer_running' check there.

DH14300
Posts: 21
Joined: Mon Sep 26, 2022 6:56 pm

Re: AOA Indexer Project

#28 Post by DH14300 »

I finally was able to fly with the new AOA code courtesy of Ralph. The indexer lights now blink if the arrestor hook is not deployed warning the pilot accurately! I adjusted the timer delay to half a second which seems to work nicely. In the meantime, I'm continuing to learn the nuances of LUA scripting and have plans to add a second device (built exactly like the AOA indexer) for the right side of my HUD which will have a nose wheel steering light, master arm and another indicator (missile warning?) of some sort.
Thanks Ralph!

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

Re: AOA Indexer Project

#29 Post by Ralph »

Glad I could help. Let us know if you need assistance with the next project.
I've just noticed that the script can be made a little bit more compact, but it works either way.

DH14300
Posts: 21
Joined: Mon Sep 26, 2022 6:56 pm

Re: AOA Indexer Project

#30 Post by DH14300 »

Using another Arduino Nano I created a new instrument on Channel B and the code works perfectly for my newest indicators. The only trouble is, in Air Manager, I can only seem to run 1 Nano at a time (either A or B). I tried using the 'Ctrl' key to select and run both Instruments but this doesn't work. What am I missing?

Post Reply