Hello,
I'm trying to make my first panel, starting from basic implementation, Arduino, 1 rotary encoder, 1 led.
I associated this LUA script to one of my Joystick button, that I press only one time, once "ready to fly" (FS2020).
COM port correctly open and function Arduino_Data correctly receive values and autopilot altitude increase or decrease correctly.
What I want to try, is, changing the taxi lights directly from inside the simulator, send the status to the Arduino and switch on or off a led.
To do this I used the offset and the function sendLightsStatus, now only for practice I always send the TAXION string to arduino, it's only an exercise to understand.
When I switch the taxi lights inside FS2020, the offset is correctly taken and the function is executed, but no bytes are sent, due the COM port seems to be busy by the event.com needed to monitor the inputs arriving from arduino.
How can I solve?
I'm a bit new to LUA and FSUIPC scripting, but not in programming in general.
Thank you
Arduino_Com_Port = com.open("COM6", 115200, 0)
if Arduino_Com_Port ~= 0 then
ipc.display("Arduino Com Port Open",5)
else
ipc.display("Could not open ARDUINO Com Port")
ipc.exit()
end
function Arduino_Data(Arduino_Com_Port, datastring, length)
if (string.find(datastring, "INC1000")) then -- Altitude up
ipc.control(65892,0)
end
if (string.find(datastring, "DEC1000")) then -- Altitude dw
ipc.control(65893,0)
end
end
function sendLightsStatus(offset, value, Arduino_Com_Port)
n = com.write(Arduino_Com_Port, "TAXION")
ipc.display("Sent: "..n)
end
event.com(Arduino_Com_Port, 50,1, "Arduino_Data") -- Monitor the serial
event.offset("0D0C", "UB", "sendLightsStatus") -- Change of taxi lights