arduino error: expected ',' or '...' before numeric constant

user2755399 picture user2755399 · Apr 10, 2014 · Viewed 17.5k times · Source

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.
enter image description here

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.

Answer

Ignacio Vazquez-Abrams picture Ignacio Vazquez-Abrams · Apr 11, 2014

The Arduino libraries use the "dataPin" and "clockPin" identifiers for their own purposes. By defining them with actual values in your code you've caused the Arduino code to become uncompilable. Rename them.

void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val);
uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder);