我现在遇到的问题是arduino uno编程软件要求我在void之前加一个逗号或分号(sketch_apr04b:16:错误:应在'void'之前加','或';'),我不知道为什么,当我这样做时,告诉我同样的答案。
这是我的代码
#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
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)
servo.write(0);
time = 0;
}
您的代码有三个语法错误:
错误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;
}
您忘记了两个';'在'int runs=0'和之后
'时间=秒*(运行*29)'。
在arduino C中,每一行都必须以结束。
您忘记了后面的分号";"
time = seconds * (runs*29)
和
int runs = 0
当您声明"runs"变量时,缺少两个";",而在"time=seconds*(runs*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;
}