标题:
请教ppm解码端口数据怎么映射到ardnio PWM接口来控制舵机
[打印本页]
作者:
kx008
时间:
2019-3-24 22:54
标题:
请教ppm解码端口数据怎么映射到ardnio PWM接口来控制舵机
1.png
(11.42 KB, 下载次数: 17)
下载附件
2019-3-25 01:55 上传
2.png
(43.76 KB, 下载次数: 23)
下载附件
2019-3-25 01:55 上传
已经解析好接收机的ppm数据,但是不知道怎么添加到程序中用arduino来控制舵机。有知道的朋友帮添加程序到数据源中
或指教。谢谢
unsigned long int a,b,c;
int x[15],ch1[15],ch[7],i;
//specifing arrays and variables to store values
void setup() {
Serial.begin(9600);
pinMode(2, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(2), read_me, FALLING);
// enabling interrupt at pin 2
}
void loop() {
read_rc();
Serial.print(ch[1]);Serial.print("\t");
Serial.print(ch[2]);Serial.print("\t");
Serial.print(ch[3]);Serial.print("\t");
Serial.print(ch[4]);Serial.print("\t");
Serial.print(ch[5]);Serial.print("\t");
Serial.print(ch[6]);Serial.print("\n");
}
void read_me() {
//this code reads value from RC reciever from PPM pin (Pin 2 or 3)
//this code gives channel values from 0-1000 values
// -: ABHILASH :- //
a=micros(); //store time value a when pin value falling
c=a-b; //calculating time inbetween two peaks
b=a; //
x[i]=c; //storing 15 value in array
i=i+1; if(i==15){for(int j=0;j<15;j++) {ch1[j]=x[j];}
i=0;}}//copy store all values from temporary array another array after 15 reading
void read_rc(){
int i,j,k=0;
for(k=14;k>-1;k--){if(ch1[k]>10000){j=k;}} //detecting separation space 10000us in that another array
for(i=1;i<=6;i++){ch[i]=(ch1[i+j]-1000);}} //assign 6 channel values after separation space
复制代码
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1