这两个数据是接口2的ppm解析数据,请教ppm解码端口数据怎么映射到ardnio PWM接口来控制舵机。在此先谢谢
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=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=(ch1[i+j]-1000);}} //assign 6 channel values after separation space
|