我在我的 Arduino 代码中看不到错误。
I can't see a mistake in my Arduino code.
这是我的代码,当我将它放入 Arduino 时 IDE 它说:
"expected primary-expression before ',' token"
我想我在某处忘记了一个点或者我在 if class.
中犯了一个小错误
非常感谢您的帮助。
代码:
#include <Servo.h>
#define trigPin 13
#define echoPin 12
#define PinOut1
Servo myservo;
int AnalogIn=A0;
int buttonState = 0;
int integer1 = 3;
float floating1 = PI;
String string1 = "words and numbers123";
int array1[5] = {100, 200, 300, 400, 500};
int PinIn1 = 2;
int PinOUt = 11;
int button = 0;
void setup() {
pinMode(PinOUt, OUTPUT);
pinMode(PinIn1, INPUT);
Serial.begin(9600);
myservo.attach(9);
}
void loop() {
Conditional1();
}
void Conditional1() {
button = digitalRead(PinIn1);
if (buttonState == HIGH) {
digitalwrite(PinOut1, HIGH);
myservo.write(60);
} else{
digitalwrite(PinOut1, LOW);
myservo.write(0);
}
}
第 4 行说
#define PinOut1
尝试添加 space 使其成为
#define PinOut 1
编辑:
在此 post 之后我还注意到了其他一些事情,所以我编译了您代码的固定版本:
#include <Servo.h>
#define trigPin 13
#define echoPin 12
#define PinOut1 11
Servo myservo;
int AnalogIn=A0;
int buttonState = 0;
int integer1 = 3;
float floating1 = PI;
String string1 = "words and numbers123";
int array1[5] = {100, 200, 300, 400, 500};
int PinIn1 = 2;
int PinOut = 11;
int button = 0;
void setup() {
pinMode(PinOut, OUTPUT);
pinMode(PinIn1, INPUT);
Serial.begin(9600);
myservo.attach(9);
}
void loop() {
Conditional1();
}
void Conditional1() {
button = digitalRead(PinIn1);
if (buttonState == HIGH) {
digitalWrite(PinOut1, HIGH);
myservo.write(60);
} else{
digitalWrite(PinOut1, LOW);
myservo.write(0);
}
}
这是我的代码,当我将它放入 Arduino 时 IDE 它说:
"expected primary-expression before ',' token"
我想我在某处忘记了一个点或者我在 if class.
中犯了一个小错误非常感谢您的帮助。
代码:
#include <Servo.h>
#define trigPin 13
#define echoPin 12
#define PinOut1
Servo myservo;
int AnalogIn=A0;
int buttonState = 0;
int integer1 = 3;
float floating1 = PI;
String string1 = "words and numbers123";
int array1[5] = {100, 200, 300, 400, 500};
int PinIn1 = 2;
int PinOUt = 11;
int button = 0;
void setup() {
pinMode(PinOUt, OUTPUT);
pinMode(PinIn1, INPUT);
Serial.begin(9600);
myservo.attach(9);
}
void loop() {
Conditional1();
}
void Conditional1() {
button = digitalRead(PinIn1);
if (buttonState == HIGH) {
digitalwrite(PinOut1, HIGH);
myservo.write(60);
} else{
digitalwrite(PinOut1, LOW);
myservo.write(0);
}
}
第 4 行说
#define PinOut1
尝试添加 space 使其成为
#define PinOut 1
编辑: 在此 post 之后我还注意到了其他一些事情,所以我编译了您代码的固定版本:
#include <Servo.h>
#define trigPin 13
#define echoPin 12
#define PinOut1 11
Servo myservo;
int AnalogIn=A0;
int buttonState = 0;
int integer1 = 3;
float floating1 = PI;
String string1 = "words and numbers123";
int array1[5] = {100, 200, 300, 400, 500};
int PinIn1 = 2;
int PinOut = 11;
int button = 0;
void setup() {
pinMode(PinOut, OUTPUT);
pinMode(PinIn1, INPUT);
Serial.begin(9600);
myservo.attach(9);
}
void loop() {
Conditional1();
}
void Conditional1() {
button = digitalRead(PinIn1);
if (buttonState == HIGH) {
digitalWrite(PinOut1, HIGH);
myservo.write(60);
} else{
digitalWrite(PinOut1, LOW);
myservo.write(0);
}
}