-8

这是我的代码,当我将其放入 Arduino IDE 时,它会显示:

“','标记之前的预期主表达式”

我想我在某个地方忘记了一个点,或者我在 if 类中犯了一个小错误。

非常感谢您的帮助。

代码:

#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

1 回答 1

2

在第 4 行它说 #define PinOut1 尝试添加一个空间来使它 #define PinOut 1

编辑:在这篇文章之后我还注意到了其他一些事情,所以我编译了你的代码的固定版本:

#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);

  }
}
于 2017-08-27T14:52:05.570 回答