I am new to arduino and C++ and am running into the above error. It seems pretty self-explanatory, however I can't find the missing comma within the code. The code worked fine before I added the binaryOut
function so I believe it is in there.
It would be nice if Arduino gave an indication of where the error is occurring.
Any help would be greatly appreciated.
#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);
}
EDIT: in Arduino HIGH and LOW are defined constants (http://arduino.cc/en/Reference/Constants) and boolean is a primitive data type (http://en.wikipedia.org/wiki/Primitive_data_type)
EDIT2: I modeled the binaryOut
from the example (shiftOut
) in the image below.
EDIT3: The exact error is:
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
I initially thought the "111" and "112" corresponded to the line number but my code has less than 90 lines.