|
楼主 |
发表于 2013-10-18 21:34:19
|
显示全部楼层
本帖最后由 yuheyan 于 2013-10-18 21:35 编辑
公布源代码供大家测试:
lua程序拷贝到FSX的module目录中,在FSUIPC4.INI文件中增加一条语句:
[Auto]
1= Lua flaptest
ino文件用arduino的IDE烧录到arduino UNO或者是nano板子上都可以,mega2560没测试过。
flaptest.lua源程序如下:
speed = 9600
handshake = 0
dev = com.open("COM36", speed, handshake) // 根据arduino的实际端口改
while 1 do
FlapRight = ipc.readSD(0x0BE4)
RFA = FlapRight * 180 / 16383
com.write(dev, string.format("%03d",RFA).."\n")
ipc.sleep(10)
end
arduino烧录程序如下:
String readString;
#include <Servo.h>
Servo myservo; // create servo object to control a servo
void setup() {
Serial.begin(9600);
myservo.attach(7); //the pin for the servo control
}
void loop() {
while (Serial.available()) {
char c = Serial.read(); //gets one byte from serial buffer
readString += c; //makes the string readString
delay(2); //slow looping to allow buffer to fill with next character
}
Serial.flush();
if (readString.length() >0) {
int n = readString.toInt(); //convert readString into a number
n = 180 - n;
myservo.write(n);
}
readString=""; //empty for next input
}
压缩包见附件
|
|