我是 arduino 和 C++ 的新手,遇到了上述错误。这似乎很不言自明,但是我在代码中找不到缺少的逗号。在我添加函数之前,代码运行良好,binaryOut
所以我相信它就在那里。
如果 Arduino 指出错误发生的位置,那就太好了。
任何帮助将不胜感激。
#define ultrasonic 6
#define buzzer 3
#define latchPin 8
#define clockPin 12
#define dataPin 11
int sound = 250;
void setup(){
Serial.begin(9600);
pinMode(buzzer, OUTPUT);
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}
void loop(){
long duration, inches;
pinMode(ultrasonic, OUTPUT);
digitalWrite(ultrasonic, LOW);
delayMicroseconds(2);
digitalWrite(ultrasonic, HIGH);
delayMicroseconds(5);
digitalWrite(ultrasonic, LOW);
pinMode(ultrasonic, INPUT);
duration = pulseIn(ultrasonic, HIGH);
inches = microsecondsToInches(duration);
if(inches > 36 || inches <= 0){
Serial.print("Out of range. ");
Serial.println(inches);
}else{
Serial.print(inches);
Serial.println(" in.");
}
binaryOut(inches);
digitalWrite(latchPin, LOW);
digitalWrite(latchPin, HIGH);
delay(1000);
}
long microsecondsToInches(long microseconds){
/* 73.746 microseconds per inch
* Sound travels at 1130 ft/s */
return microseconds/73.746/2;
}
void binaryOut(byte dataOut){
Serial.println(dataOut);
boolean pinState;
for(int i = 0; i <= 7; i++){
digitalWrite(clockPin, LOW);
if(dataOut & (1<<i)){
pinState = HIGH;
}else{
pinState = LOW;
}
digitalWrite(dataPin, pinState);
digitalWrite(clockPin, HIGH);
}
digitalWrite(clockPin, LOW);
}
编辑:在 Arduino 中,HIGH 和 LOW 是定义的常量(http://arduino.cc/en/Reference/Constants),布尔值是原始数据类型(http://en.wikipedia.org/wiki/Primitive_data_type)
EDIT2:我binaryOut
从下图中的示例(shiftOut
)中建模。
EDIT3:确切的错误是:
In file included from UltrasonicRangeSensorAJ.ino:7:
C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino/Arduino.h:111: error: expected ',' or '...' before numeric constant
C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino/Arduino.h:112: error: expected ',' or '...' before numeric constant
我最初认为“111”和“112”对应于行号,但我的代码少于 90 行。