> Arduino: expected primary-expression before '|' token?

Arduino: expected primary-expression before '|' token?

Posted at: 2014-12-18 
"X = C * (1 - |(H / 60) mod 2 - 1|);" won't happen. C language designates the '|' as the binary or function, can't be used for absolute value. To take the absolute value of something, you will need to write a C language sub routine that the chip understands to check whether it is negative and multiply it times negative 1 in that case. Something like:

'if((H / 60) mod 2 - 1) < 0)

{

X = (C * (1 - (H / 60) mod 2 - 1)* (-1));

}

else

{

X = C * (1 - (H / 60) mod 2 - 1);

}'

should probably work if you replace the line with it. I hope this helps you out. Good luck!

int potPin = 0;

int redPin = 9;

int greenPin = 10;

int val = 0;

int rval = 0;

int gval = 0;

int bval = 0;

int bluePin = 11;

int button = 2;

int button2 = 3;

int button3 = 4;

int buttonV = 0;

int button2V = 0;

int button3V = 0;

int V = 0;

int S = 0;

int H = 0;

int X = 0;

int m = 0;

//uncomment this line if using a Common Anode LED

//#define COMMON_ANODE

void setup()

{

pinMode(redPin, OUTPUT);

pinMode(greenPin, OUTPUT);

pinMode(bluePin, OUTPUT);

Serial.begin(9600);

}

void loop() {

gval = val;

val = analogRead(potPin);

float H;

float gval;

float bval;

float rval;

H = val / 360;

Serial.println(val);

Serial.print("\n");

float C;

float V;

float S;

float X;

float m;

C = V * S;

X = C * (1 - |(H / 60) mod 2 - 1|);

m = V - C;

(rval, gval, bval) = (C, X, 0) , 0 <= H < 60;

(rval, gval, bval) = (X, C, 0) , 60 <= H < 120;

(rval, gval, bval) = (0, C, X) , 120 <= H < 180;

(rval, gval, bval) = (0, X, C) , 180 <= H < 240;

(rval, gval, bval) = (X, 0, C) , 240 <= H < 300;

(rval, gval, bval) = (C, 0, X) , 300 <= H < 360;

(rval, gval, bval) = ((rval + m), (gval + m), (bval + m));

}

void setColor(int red, int green, int blue)

{

#ifdef COMMON_ANODE

red = 255 - red;

green = 255 - green;

blue = 255 - blue;

#endif

analogWrite(redPin, red);

analogWrite(greenPin, green);

analogWrite(bluePin, blue);

}

Is returning:

sketch_sep27a:60: error: expected primary-expression before '|'

sketch_sep27a:60: error: expected ')' before 'mod'

--

Any help?