我在Arduino代码中看不到错误。

时间:2017-08-27 14:47:40

标签: c arduino servo

这是我的代码,当我把它放入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);
  }
}

1 个答案:

答案 0 :(得分: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);

  }
}