標(biāo)題:
請教ppm解碼端口數(shù)據(jù)怎么映射到ardnio PWM接口來控制舵機(jī)
[打印本頁]
作者:
kx008
時(shí)間:
2019-3-24 22:54
標(biāo)題:
請教ppm解碼端口數(shù)據(jù)怎么映射到ardnio PWM接口來控制舵機(jī)
1.png
(11.42 KB, 下載次數(shù): 17)
下載附件
2019-3-25 01:55 上傳
2.png
(43.76 KB, 下載次數(shù): 23)
下載附件
2019-3-25 01:55 上傳
已經(jīng)解析好接收機(jī)的ppm數(shù)據(jù),但是不知道怎么添加到程序中用arduino來控制舵機(jī)。有知道的朋友幫添加程序到數(shù)據(jù)源中
或指教。謝謝
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
復(fù)制代碼
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1