找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 1641|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

請教ppm解碼端口數(shù)據(jù)怎么映射到ardnio PWM接口來控制舵機

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:490994 發(fā)表于 2019-3-24 22:54 | 只看該作者 |只看大圖 回帖獎勵 |倒序瀏覽 |閱讀模式

已經(jīng)解析好接收機的ppm數(shù)據(jù),但是不知道怎么添加到程序中用arduino來控制舵機。有知道的朋友幫添加程序到數(shù)據(jù)源中
或指教。謝謝

  1. unsigned long int a,b,c;
  2. int x[15],ch1[15],ch[7],i;
  3. //specifing arrays and variables to store values

  4. void setup() {
  5. Serial.begin(9600);
  6.   pinMode(2, INPUT_PULLUP);
  7.   attachInterrupt(digitalPinToInterrupt(2), read_me, FALLING);
  8.   // enabling interrupt at pin 2

  9. }

  10. void loop() {
  11. read_rc();

  12. Serial.print(ch[1]);Serial.print("\t");
  13. Serial.print(ch[2]);Serial.print("\t");
  14. Serial.print(ch[3]);Serial.print("\t");
  15. Serial.print(ch[4]);Serial.print("\t");
  16. Serial.print(ch[5]);Serial.print("\t");
  17. Serial.print(ch[6]);Serial.print("\n");


  18. }


  19. void read_me()  {
  20. //this code reads value from RC reciever from PPM pin (Pin 2 or 3)
  21. //this code gives channel values from 0-1000 values
  22. //    -: ABHILASH :-    //
  23. a=micros(); //store time value a when pin value falling
  24. c=a-b;      //calculating time inbetween two peaks
  25. b=a;        //
  26. x[i]=c;     //storing 15 value in array
  27. i=i+1;       if(i==15){for(int j=0;j<15;j++) {ch1[j]=x[j];}
  28.              i=0;}}//copy store all values from temporary array another array after 15 reading  
  29. void read_rc(){
  30. int i,j,k=0;
  31.   for(k=14;k>-1;k--){if(ch1[k]>10000){j=k;}}  //detecting separation space 10000us in that another array                     
  32.   for(i=1;i<=6;i++){ch[i]=(ch1[i+j]-1000);}}     //assign 6 channel values after separation space
復(fù)制代碼


分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復(fù) 返回頂部 返回列表