极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5277|回复: 1

请帮忙看看问题在哪?

[复制链接]
发表于 2017-3-22 17:57:30 | 显示全部楼层 |阅读模式
本帖最后由 maozx 于 2017-3-22 17:57 编辑
  1. /*

  2. This sketch is a complete radio head for FSX
  3. It needs to be used with Link2fs_Multi
  4. It was compiled with Arduino version 1.1

  5. Full project info at http://www.jimspage.co.nz/intro.htm
  6. This example code is in the public domain.
  7. Once you get this going you can experiment with removing the DELAY lines.???
  8. */


  9. #include <LiquidCrystal.h>
  10. #include "math.h"
  11. #include "Quadrature.h"
  12. Quadrature quad1(8, 9);
  13. LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
  14. int CodeIn;// used on all serial reads
  15. int X;// a rotary variable
  16. int Xold;// the old reading
  17. int Xdif;// the difference since last loop
  18. int active; // the mode thats active
  19. int activeold;
  20. int mark; // shows where the cursor is in the likes of ADF etc

  21. String oldpinStateSTR, pinStateSTR, pinStateString, APsp, APspold, stringnewstate,stringoldstate, com1, com1old, com1sb, com1sbold,com2, com2old, com2sb,com2sbold, airsp, airspold, altit, altitold;
  22. String nav1, nav1old, nav1sb, nav1sbold, nav2, nav2old, nav2sb, nav2sbold;
  23. String adf, adfold, xpdr, xpdrold, dme1, dme1old, dme2, dme2old, pitot, pitotold;
  24. char blank = 255;

  25. void setup()
  26. {
  27.   lcd.begin(16, 2); // set up the LCD's number of columns and rows:
  28.   stringoldstate = "111111111111111111111111111111111111111111111111111111111111111111111";
  29.   Serial.begin(115200);
  30.   for (int doutPin = 10; doutPin <= 19; doutPin++) // setup the input pins
  31.   {  
  32.     pinMode(doutPin, INPUT);
  33.     digitalWrite(doutPin, HIGH);  
  34.   }  
  35.   mark = 10;
  36.   lcd.clear();
  37. }

  38. void loop() {
  39.    {INPUTPINS();} //Check the "button pressed" section
  40.    {LCDMODE();}  // Sets up the LCD for the mode it's in (From the rotary switch)
  41.    {ROTARYS();} // go and check the rotary encoder
  42.   if (Serial.available()) { // now lets check the serial buffer for any input data
  43.     CodeIn = getChar();
  44.     if (CodeIn == '=') {EQUALS();}// The first identifier is "="
  45.   } // end of serial available
  46. }// edn of void loop

  47. char getChar()// Get a character from the serial buffer
  48. {
  49.   while(Serial.available() == 0);// wait for data
  50.   return((char)Serial.read());// Thanks Doug
  51. }//end of getchar

  52. void LCDMODE(){
  53. if (active != activeold)
  54.     activeold = active;
  55.   if (digitalRead(12)==0 and active != 12) { // Sets up the LCD when switching to Com1)
  56.     lcd.setCursor(0, 0);
  57.     delay (11);
  58.     lcd.print("Com.1    ");
  59.     lcd.setCursor(9, 0);
  60.     delay (11);
  61.     lcd.print(com1);
  62.     lcd.setCursor(0, 1);
  63.     delay (11);
  64.     lcd.print("  s/b    ");
  65.     lcd.setCursor(9, 1);
  66.     delay (11);
  67.     lcd.print(com1sb);
  68.     active = 12;
  69.   }

  70.   if (digitalRead(14)==0 and active != 14) {  // Sets up the LCD when switching to Com2)
  71.     lcd.setCursor(0, 0);
  72.     delay (11);
  73.     lcd.print("Com.2    ");  
  74.     lcd.setCursor(9, 0);
  75.     delay (11);
  76.     lcd.print(com2);
  77.     lcd.setCursor(0, 1);
  78.     lcd.print("  s/b    ");
  79.     lcd.setCursor(9, 1);
  80.     delay (11);
  81.     lcd.print(com2sb);
  82.     active = 14;
  83.   }

  84.   if (digitalRead(15)==0 and active != 15) {  // Sets up the LCD when switching to Nav1)
  85.     lcd.setCursor(0, 0);
  86.     delay (11);
  87.     lcd.print("Nav.1    ");  
  88.     lcd.setCursor(9, 0);
  89.     delay (11);
  90.     lcd.print(nav1);
  91.     lcd.setCursor(0, 1);
  92.     lcd.print("  s/b    ");
  93.     lcd.setCursor(9, 1);
  94.     delay (11);
  95.     lcd.print(nav1sb);
  96.     active = 15;
  97.   }
  98.   if (digitalRead(16)==0 and active != 16) {  // Sets up the LCD when switching to Nav2)
  99.     lcd.setCursor(0, 0);
  100.     delay (11);
  101.     lcd.print("Nav.2    ");  
  102.     lcd.setCursor(9, 0);
  103.     delay (11);
  104.     lcd.print(nav2);
  105.     lcd.setCursor(0, 1);
  106.     lcd.print("  s/b    ");
  107.     lcd.setCursor(9, 1);
  108.     delay (11);
  109.     lcd.print(nav2sb);
  110.     active = 16;
  111.   }   
  112.   if (digitalRead(17)==0 and active != 17) {  // Sets up the LCD when switching to ADF)
  113.     lcd.setCursor(0, 0);
  114.     delay (11);
  115.     lcd.print("ADF      ");  
  116.     lcd.setCursor(9, 0);
  117.     delay (11);
  118.     lcd.print(adf);
  119.     lcd.print("  ");
  120.     lcd.setCursor(0, 1);
  121.     lcd.print("                ");
  122.     if (mark == 9 ){mark = 10;}
  123.     lcd.setCursor(mark, 1);
  124.     lcd.print("-");
  125.     active = 17;            
  126.   }   
  127.   if (digitalRead(18)==0 and active != 18) {  // Sets up the LCD when switching to DME)
  128.     lcd.setCursor(0, 0);
  129.     delay (11);
  130.     lcd.print("DME1     ");  
  131.     lcd.setCursor(9, 0);
  132.     delay (11);
  133.     lcd.print(dme1);
  134.     lcd.print("  ");
  135.     lcd.setCursor(0, 1);
  136.     lcd.print("DME2     ");
  137.     lcd.setCursor(9, 1);
  138.     delay (11);
  139.     lcd.print(dme2);
  140.     active = 18;
  141.   }        
  142.   if (digitalRead(19)==0 and active != 19) {  // Sets up the LCD when switching to XPDR)
  143.     lcd.setCursor(0, 0);
  144.     delay (11);
  145.     lcd.print("XPonder  ");  
  146.     lcd.setCursor(9, 0);
  147.     delay (11);
  148.     lcd.print(xpdr);
  149.     //lcd.print("    ");
  150.     lcd.setCursor(0, 1);
  151.     lcd.print("                ");
  152.     lcd.setCursor(mark, 1);
  153.     lcd.print("-");
  154.     active = 19;                  
  155.    }         
  156.   } // end of LCDmode

  157. void EQUALS(){      // The first identifier was "="
  158.        delay (11);
  159.        CodeIn = getChar(); // Get another character
  160.   switch(CodeIn) {// Now lets find what to do with it
  161.     case 'A'://Found the second identifier "Com1"
  162.         com1 = "";
  163.         com1 += getChar();
  164.         com1 += getChar();
  165.         com1 += getChar();
  166.         com1 += getChar();
  167.         com1 += getChar();
  168.         com1 += getChar();
  169.         com1 += getChar();
  170.         if (com1 != com1old && digitalRead(12) == LOW) {
  171.           delay (11);
  172.           lcd.setCursor(9, 0);
  173.           delay (11);
  174.           lcd.print(com1);
  175.           com1old = com1;
  176.           }
  177.          break;
  178.       case 'B': // Found the reading "Com1 s/b"
  179.         com1sb = "";
  180.         com1sb += getChar();
  181.         com1sb += getChar();
  182.         com1sb += getChar();
  183.         com1sb += getChar();
  184.         com1sb += getChar();
  185.         com1sb += getChar();
  186.         com1sb += getChar();
  187.         if (com1sb != com1sbold && digitalRead(12) == LOW ){
  188.           delay (11);
  189.           lcd.setCursor(9, 1);
  190.           delay (11);
  191.           lcd.print(com1sb);
  192.           com1sbold = com1sb;
  193.           }        
  194.          break;
  195.        case  'C': //  Found the reading "Com2"
  196.         com2 = "";
  197.         com2 += getChar();
  198.         com2 += getChar();
  199.         com2 += getChar();
  200.         com2 += getChar();
  201.         com2 += getChar();
  202.         com2 += getChar();
  203.         com2 += getChar();
  204.         if (com2 != com2old && digitalRead(14) == LOW) {
  205.           lcd.setCursor(9, 0);
  206.           delay (11);
  207.           lcd.print(com2);
  208.           com2old = com2;
  209.           }
  210.          break;
  211.        case  'D': //  Found the reading "Com2 s/b"
  212.         com2sb = "";
  213.         com2sb += getChar();
  214.         com2sb += getChar();
  215.         com2sb += getChar();
  216.         com2sb += getChar();
  217.         com2sb += getChar();
  218.         com2sb += getChar();
  219.         com2sb += getChar();
  220.         if (com2sb != com2sbold && digitalRead(14) == LOW) {
  221.           lcd.setCursor(9, 1);
  222.           delay (11);
  223.           lcd.print(com2sb);
  224.           com2sbold = com2sb;
  225.           }
  226.          break;         
  227.        case  'E': //  Found the reading "Nav1"
  228.         delay (11);
  229.         nav1 = "";
  230.         nav1 += getChar();
  231.         nav1 += getChar();
  232.         nav1 += getChar();
  233.         nav1 += getChar();
  234.         nav1 += getChar();
  235.         nav1 += getChar();
  236.         nav1 += (" "); //pads it up to 8 caracters
  237.         if (nav1 != nav1old && digitalRead(15) == LOW) {
  238.           lcd.setCursor(9, 0);
  239.           delay (11);
  240.           lcd.print(nav1);
  241.           nav1old = nav1;
  242.           }
  243.          break;
  244.        case  'F': //  Found the reading "Nav1 s/b"
  245.         nav1sb = "";
  246.         nav1sb += getChar();
  247.         nav1sb += getChar();
  248.         nav1sb += getChar();
  249.         nav1sb += getChar();
  250.         nav1sb += getChar();
  251.         nav1sb += getChar();
  252.         nav1sb += (" "); //pads it up to 8 caracters
  253.         if (nav1sb != nav1sbold && digitalRead(15) == LOW) {
  254.           lcd.setCursor(9, 1);
  255.           delay (11);
  256.           lcd.print(nav1sb);
  257.           nav1sbold = nav1sb;
  258.           }              
  259.          break;
  260.        case  'G': //  Found the reading "Nav2"
  261.         delay (11);
  262.         nav2 = "";
  263.         nav2 += getChar();
  264.         nav2 += getChar();
  265.         nav2 += getChar();
  266.         nav2 += getChar();
  267.         nav2 += getChar();
  268.         nav2 += getChar();
  269.         nav2 += (" "); //pads it up to 8 caracters
  270.         if (nav2 != nav2old && digitalRead(16) == LOW) {
  271.           lcd.setCursor(9, 0);
  272.           delay (11);
  273.           lcd.print(nav2);
  274.           nav2old = nav2;
  275.           }
  276.          break;
  277.        case  'H': //  Found the reading "Nav2 s/b"
  278.         nav2sb = "";
  279.         nav2sb += getChar();
  280.         nav2sb += getChar();
  281.         nav2sb += getChar();
  282.         nav2sb += getChar();
  283.         nav2sb += getChar();
  284.         nav2sb += getChar();
  285.         nav2sb += (" "); //pads it up to 8 caracters
  286.         if (nav2sb != nav2sbold && digitalRead(16) == LOW) {
  287.           lcd.setCursor(9, 1);
  288.           delay (11);
  289.           lcd.print(nav2sb);
  290.           nav2sbold = nav2sb;
  291.           }              
  292.          break;
  293.        case  'I': //  Found the reading "ADF"
  294.         adf = "";
  295.         adf += getChar();
  296.         adf += getChar();
  297.         adf += getChar();
  298.         adf += getChar();
  299.         adf += getChar();
  300.         adf += getChar();
  301.         adf += (" "); //pads it up to 8 caracters
  302.         if (adf != adfold && digitalRead(17) == LOW) {
  303.           lcd.setCursor(9, 0);
  304.           delay (11);
  305.           lcd.print(adf);
  306.           adfold = adf;
  307.           }
  308.          break;   
  309.        case  'J': //  Found the reading "XPDR"
  310.         delay (11);
  311.         xpdr = "";
  312.         xpdr += getChar();
  313.         xpdr += getChar();
  314.         xpdr += getChar();
  315.         xpdr += getChar();
  316.         xpdr += ("    "); //pads it up to 8 caracters
  317.         if (xpdr != xpdrold && digitalRead(19) == LOW) {
  318.           lcd.setCursor(9, 0);
  319.           delay (11);
  320.           lcd.print(xpdr);
  321.           xpdrold = xpdr;
  322.           }               
  323.          break;
  324.        case  'K': //  Found the reading "DME1"
  325.         delay (11);
  326.         dme1 = "";
  327.         dme1 += getChar();
  328.         dme1 += getChar();
  329.         dme1 += getChar();
  330.         dme1 += getChar();
  331.         dme1 += getChar();
  332.         dme1 += ("   "); //pads it up to 8 caracters
  333.         if (dme1 != dme1old && digitalRead(18) == LOW) {
  334.           lcd.setCursor(9, 0);
  335.           delay (11);
  336.           lcd.print(dme1);
  337.           dme1old = dme1;
  338.           }
  339.          break;         
  340.        case  'L': //  Found the reading "DME2"
  341.         delay (11);
  342.         dme2 = "";
  343.         dme2 += getChar();
  344.         dme2 += getChar();
  345.         dme2 += getChar();
  346.         dme2 += getChar();
  347.         dme2 += getChar();
  348.         dme2 += ("   "); //pads it up to 8 caracters
  349.         if (dme2 != dme2old && digitalRead(18) == LOW) {
  350.           lcd.setCursor(9, 1);
  351.           delay (11);
  352.           lcd.print(dme2);
  353.           dme2old = dme2;
  354.         }
  355.         break;
  356.       }               
  357.     }

  358.   void ROTARYS() {//now the bit for the rotary encoder input
  359.   X =(quad1.position()/2);
  360.   if (X != Xold) { // checks to see if it different
  361.     (Xdif = (X-Xold));// finds out the difference
  362.     //lcd.setCursor(0, 0);

  363.     if (active == 12){// Com1 rotary encoder output
  364.       if (Xdif == 1) {
  365.         if (digitalRead(10)==0 ) {
  366.           Serial.println("A01");
  367.         }
  368.         else Serial.println("A03");
  369.       }
  370.       if (Xdif == -1) {
  371.         if (digitalRead(10)==0 ) {
  372.           Serial.println("A02");
  373.         }
  374.         else Serial.println("A04");
  375.       }
  376.     }
  377.     if (active == 14){// Com2 rotary encoder output
  378.       if (Xdif == 1) {
  379.         if (digitalRead(10)==0 ) {
  380.           Serial.println("A07");
  381.         }
  382.         else Serial.println("A09");
  383.       }
  384.       if (Xdif == -1) {
  385.         if (digitalRead(10)==0 ) {
  386.           Serial.println("A08");
  387.         }
  388.         else Serial.println("A10");
  389.       }
  390.     }
  391.     if (active == 15){// Nav1 rotary encoder output
  392.       if (Xdif == 1) {
  393.         if (digitalRead(10)==0 ) {
  394.           Serial.println("A13");
  395.         }
  396.         else Serial.println("A15");
  397.       }
  398.       if (Xdif == -1) {
  399.         if (digitalRead(10)==0 ) {
  400.           Serial.println("A14");
  401.         }
  402.         else Serial.println("A16");
  403.       }
  404.     }
  405.     if (active == 16){// Nav2 rotary encoder output
  406.       if (Xdif == 1) {
  407.         if (digitalRead(10)==0 ) {
  408.           Serial.println("A19");
  409.         }
  410.         else Serial.println("A21");
  411.       }
  412.       if (Xdif == -1) {
  413.         if (digitalRead(10)==0 ) {
  414.           Serial.println("A20");
  415.         }
  416.         else Serial.println("A22");
  417.       }
  418.     }
  419.     if (active == 17){// ADF rotary encoder output
  420.       if (digitalRead(10)==0 ) {
  421.         if (Xdif == 1) {
  422.           mark = (mark - 1);
  423.           active = 2;
  424.           if (mark == 13) mark =12;
  425.         }
  426.         if (Xdif == -1){
  427.           mark = (mark + 1);
  428.           active = 2;
  429.           if (mark == 13) mark =14;
  430.         }
  431.         if (mark > 14) mark = 14;
  432.         if (mark < 10) mark = 10;
  433.       }
  434.       else{
  435.         if (Xdif == 1) {
  436.           if (mark == 10) {
  437.             Serial.println("A29");
  438.           }
  439.           if (mark == 11) {
  440.             Serial.println("A30");
  441.           }
  442.           if (mark == 12) {
  443.             Serial.println("A31");
  444.           }
  445.           if (mark == 14) {
  446.             Serial.println("A32");
  447.           }
  448.         }   
  449.         if (Xdif == -1){
  450.           if (mark == 10){
  451.             Serial.println("A25");
  452.           }  
  453.           if (mark == 11){
  454.             Serial.println("A26");
  455.           }  
  456.           if (mark == 12){
  457.             Serial.println("A27");
  458.           }  
  459.           if (mark == 14){
  460.             Serial.println("A28");
  461.           }  
  462.         }
  463.       }
  464.     }
  465.     if (active == 19){// Xponder rotary encoder output
  466.       if (digitalRead(10)==0 ) {
  467.         if (Xdif == 1) {
  468.           mark = (mark - 1);
  469.           active = 2;
  470.         }
  471.         if (Xdif == -1){
  472.           mark = (mark + 1);
  473.           active = 2;
  474.         }
  475.         if (mark > 12) mark = 12;
  476.         if (mark < 9) mark = 9;
  477.       }
  478.       else{
  479.         if (Xdif == 1) {
  480.           if (mark == 9) {
  481.             Serial.println("A38");
  482.           }
  483.           if (mark == 10) {
  484.             Serial.println("A39");
  485.           }
  486.           if (mark == 11) {
  487.             Serial.println("A40");
  488.           }
  489.           if (mark == 12) {
  490.             Serial.println("A41");
  491.           }
  492.         }   
  493.         if (Xdif == -1){
  494.           if (mark == 9){
  495.             Serial.println("A34");
  496.           }  
  497.           if (mark == 10){
  498.             Serial.println("A35");
  499.           }  
  500.           if (mark == 11){
  501.             Serial.println("A36");
  502.           }  
  503.           if (mark == 12){
  504.             Serial.println("A37");
  505.           }  
  506.         }
  507.       }   
  508.     }

  509.     if (quad1.position() > 100){ // zero the rotary encoder count if too high or low
  510.       quad1.position(0);
  511.     }
  512.     if (quad1.position() < -100){
  513.       quad1.position(0);
  514.     }
  515.     Xold = X; // overwrites the old reading with the new one.
  516.     }
  517.   }// end of rotarys
  518.   
  519. void INPUTPINS(){
  520.   stringnewstate = "";
  521.   for (int pinNo = 10; pinNo <= 19; pinNo++){
  522.     pinStateSTR = String(digitalRead(pinNo));
  523.     oldpinStateSTR = "";
  524.     oldpinStateSTR += String(stringoldstate.charAt(pinNo - 10));
  525.     if (pinStateSTR != oldpinStateSTR) {
  526.       if (pinNo == 11 and pinStateSTR == "0") { //Change-over button pressed
  527.         if (active == 12) Serial.println("A06");
  528.         if (active == 14) Serial.println("A12");
  529.         if (active == 15) Serial.println("A18");
  530.         if (active == 16) Serial.println("A24");
  531.         if ( active == 17){
  532.           mark = (mark + 1);
  533.           if (mark == 13){
  534.             mark = 14;
  535.           }// sort out for piont in ADF
  536.           active = 1;
  537.           if (mark > 14)mark = 10;
  538.         }
  539.         if  (active == 19){
  540.           mark = (mark + 1);
  541.           if (mark == 13){
  542.             mark = 9;
  543.           }// sort out for length Xponder
  544.           active = 1;
  545.           if (mark > 12)mark = 12;
  546.         }
  547.       } // end of "if it's pin ??" do something
  548.     }// end of "yes it's different"
  549. stringnewstate += pinStateSTR;
  550.   }
  551.   stringoldstate = stringnewstate;
  552.     delay(11);
  553. }// end of inputpins


复制代码







Arduino:1.8.1 (Windows 7), 开发板:"Arduino/Genuino Uno"

D:\Documents\Arduino\libraries\Multi_Radiohead_Uno\Multi_Radiohead_Uno.ino:15:24: fatal error: Quadrature.h: No such file or directory

#include "Quadrature.h"

                        ^

compilation terminated.

exit status 1
为开发板 Arduino/Genuino Uno 编译时出错。

在文件 -> 首选项开启
“编译过程中显示详细输出”选项
这份报告会包含更多信息。
回复

使用道具 举报

发表于 2017-3-22 21:58:09 | 显示全部楼层
缺少文件Quadrature.h,你需要把这个文件放到安装目录下的library文件夹里面才可以,如果你是网上买的,请找卖家索取有关文件
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-3-29 20:02 , Processed in 0.048060 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表