arduino语法代码错误

时间:2016-04-06 09:20:50

标签: arduino arduino-uno

我现在面临的问题是arduino uno编程软件要求我在无效之前插入逗号或分号(sketch_apr04b:16:错误:预期','或';'在'void'之前),我不会知道为什么以及何时这样做会告诉我相同的答案。

这是我的代码

Array
(
    [success] => 1
    [pagename] => RC1_PGR_Questions
    [result] => Array
        (
            [CurrentInsuranceStatus] => Array
                (
                    [QuestionData] => Platform_Form_Page_Question Object
                        (
                            [_answer] => 
                            [_answerOptions] => Array
                                (
                                    [0] => Platform_Form_Page_Question_AnswerOption Object
                                        (
                                            [_answerKey] => 340280
                                            [_hideAnswer] => 1
                                            [_order] => 110
                                            [_promptText] => Yes
                                            [_value] => Y
                                            [_errorLog] => Array
                                                (
                                                )

                                        )

                                    [1] => Platform_Form_Page_Question_AnswerOption Object
                                        (
                                            [_answerKey] => 340290
                                            [_hideAnswer] => 
                                            [_order] => 120
                                            [_promptText] => Yes, on parent's policy
                                            [_value] => Parents
                                            [_errorLog] => Array
                                                (
                                                )

                                        )

                                    [2] => Platform_Form_Page_Question_AnswerOption Object
                                        (
                                            [_answerKey] => 340300
                                            [_hideAnswer] => 
                                            [_order] => 130
                                            [_promptText] => Yes, insured through employer
                                            [_value] => Company
                                            [_errorLog] => Array
                                                (
                                                )

                                        )

                                    [3] => Platform_Form_Page_Question_AnswerOption Object
                                        (
                                            [_answerKey] => 340310
                                            [_hideAnswer] => 
                                            [_order] => 140
                                            [_promptText] => No, policy lapsed/expired
                                            [_value] => Lapsed
                                            [_errorLog] => Array
                                                (
                                                )

                                        )

                                    [4] => Platform_Form_Page_Question_AnswerOption Object
                                        (
                                            [_answerKey] => 340320
                                            [_hideAnswer] => 
                                            [_order] => 150
                                            [_promptText] => No, never been insured
                                            [_value] => Never
                                            [_errorLog] => Array
                                                (
                                                )

                                        )

                                    [5] => Platform_Form_Page_Question_AnswerOption Object
                                        (
                                            [_answerKey] => 340330
                                            [_hideAnswer] => 
                                            [_order] => 160
                                            [_promptText] => No, I didn't have a vehicle to insure
                                            [_value] => First
                                            [_errorLog] => Array
                                                (
                                                )

                                        )

                                    [6] => Platform_Form_Page_Question_AnswerOption Object
                                        (
                                            [_answerKey] => 340340
                                            [_hideAnswer] => 
                                            [_order] => 170
                                            [_promptText] => No, been deployed/overseas in the military
                                            [_value] => Military
                                            [_errorLog] => Array
                                                (
                                                )

                                        )

                                    [7] => Platform_Form_Page_Question_AnswerOption Object
                                        (
                                            [_answerKey] => 340350
                                            [_hideAnswer] => 
                                            [_order] => 180
                                            [_promptText] => No, other reason
                                            [_value] => Other
                                            [_errorLog] => Array
                                                (
                                                )

                                        )

                                )

                            [_answersDivID] => html_CurrentInsuranceStatus
                            [_phoneAreaField] => 
                            [_attributeName] => CurrentInsuranceStatus
                            [_criteriaBasedQuestion] => 1
                            [_dateField] => 
                            [_eventHandler] => 
                            [_fieldType] => select
                            [_hideQuestion] => 1
                            [_monthField] => 
                            [_phoneNumberField] => 
                            [_order] => 10000
                            [_pageAttributes] => stdClass Object
                                (
                                    [additionalLabel] => 
                                    [answerStyle] => 
                                    [colNum] => 
                                    [colWidth] => 
                                    [cssclass] => 
                                    [defaultValue] => 
                                    [isMultiSelect] => 
                                    [maxLength] => 
                                    [min] => 
                                    [questionSkinStyle] => 
                                    [toolTip] => 
                                )

                            [_phonePreFixField] => 
                            [_questionDivID] => prompt_CurrentInsuranceStatus
                            [_questionKey] => 7169010
                            [_required] => 1
                            [_text] => Current insurance status
                            [_yearField] => 
                            [_errorLog] => Array
                                (
                                )

                        )

                )

        )

)

4 个答案:

答案 0 :(得分:1)

您的代码有三个语法错误:

错误1:

所有分号都用于标记语句的结束。 #include不是声明,因此不应包含分号。

错误2和3:

与分号之前一样用于语句的分隔符。然后你应该把它包含在两行中。

#include <Servo.h>;  <----------------------- ERROR 1

Servo servo;

void setup () {
  servo.attach(9);
  servo.write(0);
  Serial.begin(9600);
}

  int seconds = millis()/1000;
  int degs = 0;
  int time = 0;
  int runs = 0 <----------------------------- ERROR 2

void loop() {
  // put your main code here, to run repeatedly:
  seconds = millis();
  while(time <= 28) {
  Serial.write(seconds);
  degs = map(time, 0, 29, 0, 179);
  servo.write(degs);
  delay(1000);
  }
  runs = runs + 1;
  time = seconds * (runs*29) <--------------- ERROR 3
  servo.write(0);
  time = 0;
}

答案 1 :(得分:0)

你忘记了两个&#39 ;;&#39;在&#39; int runs = 0 ; &#39;之后的代码中之后

&#39;时间=秒*(运行* 29); &#39;。

在arduino C中,每一行必须以; 完成。

答案 2 :(得分:0)

你忘记了分号,“;”在这些行之后

time = seconds * (runs*29)

int runs = 0

答案 3 :(得分:0)

你错过了两个“;”当你声明'runs'变量,并在'time = seconds *(运行* 29)'

    #include <Servo.h>;  

    Servo servo;

    void setup () {
      servo.attach(9);
      servo.write(0);
      Serial.begin(9600);
    }

      int seconds = millis()/1000;
      int degs = 0;
      int time = 0;
      int runs = 0 <---- HERE
void loop() {
  // put your main code here, to run repeatedly:
  seconds = millis();
  while(time <= 28) {
  Serial.write(seconds);
  degs = map(time, 0, 29, 0, 179);
  servo.write(degs);
  delay(1000);
  }
  runs = runs + 1;
  time = seconds * (runs*29)<----- HERE
  servo.write(0);
  time = 0;
}