-- LUA To Arduino Script File By Trevor Hale http://www.cockpitbuilders.com -- Varialble Declare foot =3.28083989501312 abv=0 fkey = 115 -- F4 is 115 -- F7 is 118 snd=0 snd2=0 snd3=1 snd4=0 snd5=0 red_string = "" commands={} -- Open Seial Port and connect to Arduino speed = 115200 handshake = 0 serial_wait = 20 old_value = 0 x = 0 inited = 0 states = {} dev = com.open("COM3", speed, handshake) -- Change Port Number for your Arduino if dev == 0 then ipc.display("Could not open device port") ipc.exit() end -- Finish Serial Connect gfd.SetBright(GFRP48, 0, 15) -- Callbacks function call_vertical (offset, value) value = (((value*60)*3.28084)/256) -- ipc.log ("writes com = =4113 then gfd.SetLight(GFRP48, 0, 1) else if value <=3175 then gfd.SetLight(GFRP48, 0, 1) else gfd.ClearLight(GFRP48, 0, 1) end end ipc.sleep(serial_wait) end function call_roilp (offset, value) if value <=11500 then gfd.SetLight(GFRP48, 0, 2) else gfd.ClearLight(GFRP48, 0, 2) end ipc.sleep(serial_wait) end function call_rfuelp (offset, value) if value <=850 then gfd.SetLight(GFRP48, 0, 3) else gfd.ClearLight(GFRP48, 0, 3) end ipc.sleep(serial_wait) end function call_lfuelp (offset, value) if value <=850 then -- ipc.display(value) gfd.SetLight(GFRP48, 0, 4) else gfd.ClearLight(GFRP48, 0, 4) end ipc.sleep(serial_wait) end function call_loilp (offset, value) if value <=11500 then gfd.SetLight(GFRP48, 0, 5) else gfd.ClearLight(GFRP48, 0, 5) end ipc.sleep(serial_wait) end function call_invert1 (offset, value) if value ==0 then gfd.SetLight(GFRP48, 0, 6) else gfd.ClearLight(GFRP48, 0, 6) end ipc.sleep(serial_wait) end function call_invert2 (offset, value) if value ==0 then gfd.SetLight(GFRP48, 0, 6) else gfd.ClearLight(GFRP48, 0, 6) end ipc.sleep(serial_wait) end function call_apdisc (offset, value) if value ==1 then gfd.SetLight(GFRP48, 0, 7) else gfd.ClearLight(GFRP48, 0, 7) end ipc.sleep(serial_wait) end -- SCENE CHANGER function Scene_Check (ms_time) pkg = ipc.readDBL(0x0bc8) pkg = tonumber(string.format("%.0f", pkg)) alt = ipc.readDBL(0x6020) alt = alt * 3.28083989501312 alt = tonumber(string.format("%.0f", alt)) gnd = ipc.readDBL(0x0020) gnd = gnd * 3.28083989501312 gnd = tonumber(string.format("%.0f", gnd)) speed = ipc.readUD(0x02BC) speed = speed/128 speed = tonumber(string.format("%.0f", speed)) vsi = ipc.readSD(0x02c8) vsi = (((vsi*60)*3.28084)/256) vsi = tonumber(string.format("%.0f", vsi)) ongnd = ipc.readUW(0x0366) ongnd = tonumber(string.format("%.0f", ongnd)) if (alt < 10000) then if (speed > 40 and fkey == 115) then ipc.keypress(118) --press F7 fkey = 118 abv=0 --ipc.display(fkey) end if (speed < 20 and fkey == 118) then ipc.keypress(115) --press F4 fkey = 115 --ipc.display(fkey) end end if (alt > 10000 and abv==0) then ipc.keypress(115) --press F4 fkey = 115 abv=1 --ipc.display(fkey) end -- sound calls if (alt < 8000) and (alt > 7500) and (vsi < 0) and (snd5 == 0) then sound.play("cb_Descent.wav",2) snd5 = 1 end if (alt > 8000) and (alt < 8500) and (vsi > 0) and (snd5 == 1) then snd5 = 0 end if (ongnd == 1) and (speed > 10) and (snd4 == 0) then sound.play("cb_Safety_Briefing.wav",2) snd4 = 1 end if (pkg == 32767) and (ongnd == 1) and (speed < 10) then snd4 = 0 end if (ongnd ==1 ) and (speed < 40) and (snd3 == 0) then sound.play("cb_Gatearr.wav",2) snd3 = 1 end if (ongnd == 0) and (alt > 1000) and (snd3 == 1) then snd3 = 0 end if (alt > 21000) and (alt < 21500) and (vsi > 0) and (snd2 == 0) then sound.play("cb_Cruise.wav",2) snd2 = 1 end if (alt < 21500) and (alt > 21000) and (vsi < 0) and (snd2 == 1) then snd2 = 0 end if (alt < 10900) and (alt > 10500) and (vsi < 0) and (snd == 0) then sound.play("cb_Approach.wav",2) snd = 1 end if (alt > 10500) and (alt < 10900) and (vsi > 0) and (snd == 1) then snd = 0 end ipc.sleep(20) end -- TIMER FOR SCENE CHANGE event.timer(1000, "Scene_Check") -- GOFLIGHT LIGHTS event.offset (0x31E4, "UD", "call_altwarn") -- ALT WARN event.offset (0x0BC0, "SW", "call_trimlight") -- TRIM WARN event.offset (0x0952, "UW", "call_roilp") -- R OIL PRESS event.offset (0x0990, "UD", "call_rfuelp") -- R FUEL PRESS event.offset (0x08F8, "UD", "call_lfuelp") -- L FUEL PRESS event.offset (0x08BA, "UW", "call_loilp") -- L OIL PRESS event.offset (0x3ABC, "UD", "call_invert2") -- Inverter Gen2 event.offset (0x3B7C, "UD", "call_invert1") -- Inverter Gen1 event.offset (0x5414, "UD", "call_apdisc") -- AP DISCO -- Arduino Gauges/Servos event.offset (0x2880, "DBL", "call_gen1") -- Gen1 event.offset (0x2890, "DBL", "call_gen2") -- Gen2 event.offset (0x0be0, "UD", "call_flaps") -- aircraft Flaps event.offset (0x02c8, "SD", "call_vertical") -- aircraft Vertical Speed event.offset (0x0b7c, "UD", "call_lfuel") -- aircraft Left Fuel event.offset (0x2824, "DBL", "call_prop") -- Prop Amps event.offset (0x02CC, "DBL", "call_hed") --compass event.offset (0x0b94, "UD", "call_rfuel") -- aircraft Right Fuel event.offset (0x0bc2, "SW", "call_trim") -- aircraft Trim event.offset (0x0e8c, "SW", "call_oat") -- aircraft Outside Air Temp event.offset (0x2840, "DBL", "call_bat") -- Bat event.offset (0x2888, "DBL", "call_load1") -- Load1 event.offset (0x2898, "DBL", "call_load2") -- Load2