:thumbup:
I can't speak english very good.
Sorry for using the google translator.
I am creating a library "export.dll" for connecting the arduino directly to sim.
:joystick:
This is a beta, to test put the library in the bin folder of the sim. Export.rar is on attached file.
In the export.lua:
require("export") --load the library
opencom()-- open the serial port and configure it has 115200 bps.
example: opencom("COM7")
opencom() requires the Arduino will send the word "conected" at startup to continue. Serial.print("conected
");
See my arduino sketch.
writecom() -- send data to the serial port example: writecom("HelloWorld")
readcom() -- read the serial port example: print(readcom())
closecom() -- close the serial port
My export.lua example:
require("export") --load the library
function LuaExportStart()
opencom("COM7") --abrimos el puerto y esperamos a que el arduino envie el comando "conected"
end
function LuaExportBeforeNextFrame()
command = readcom() -- leemos datos del puerto serie y si corresponde con down o up le mandamos al sim que suba o baje el tren de aterrizaje.
if command == "down" then
LoSetCommand(431)
elseif command == "up" then
LoSetCommand(430)
end
end
function LuaExportAfterNextFrame()
local altBar = LoGetAltitudeAboveSeaLevel() --leemos la altura del sim
writecom(string.format("AltBar %2.fM.",altBar)) -- y la mandamos por el puerto serie
end[/center]
function LuaExportStop()
closecom() --cerramos el puerto serie
end
My arduino sketch:
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
char caracter;
byte i=0;
char cadena[100];
int val = 0;
void setup()
{
Serial.begin(115200); //Configuramos puerto serie
lcd.begin(16, 2);
lcd.clear();
lcd.print("Arduino OK");
Serial.print("conected
"); //Enviamos conected por el puerto serie
}
void loop()
{
if(Serial.available()) // si hay algo en el puerto serie lo imprimimos por pantalla
{
caracter=Serial.read();
if (caracter == 10)
{
cadena[i++]='';
i=0;
if(!strcmp(cadena,"state"))
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Conected to DCS");
}
else
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(cadena);
}
}
else
cadena[i++]=caracter;
}
val = analogRead(0); //leemos los botones del arduinop y mandamos el comando por el puerto serie
if (val > 75 && val < 200)
{
Serial.print("up");
delay(200);
}
if (val > 200 && val < 350)
{
Serial.print("down");
delay(200);
}
}
:pilotfly: export.rar