Go Down

Topic: Help with error (Read 473 times) previous topic - next topic

rushy

Hi, I seem to be struggling with my program when I try and verify my code is return the following error:

photocell.cpp: In function 'void loop()':
photocell.cpp:22:32: error: expected primary-expression before '<' token
if (percentage < 33) {
^

Any help would be much appreciated, thanks

Code: [Select]
int red = D0;
int green = D2;
int blue = D1;

void setup() {
pinMode(red, OUTPUT);
pinMode(green, OUTPUT);
pinMode(blue, OUTPUT);

}

void loop() {
    int value = analogRead(A0);

    int percentage = map(value, 0, 4095, 0, 100);
   
if (percentage < 33) {
    digitalWrite(green, HIGH);
    digitalWrite(red, LOW);
    digitalWrite(blue, LOW);
}
    else if (percentage > 33 & < 66) {
        digitalWrite(green, LOW);
        digitalWrite(red, LOW);
        digitalWrite(blue, HIGH);
    }   
    else if (percentage > 66) {
        digitalWrite(green, LOW);
        digitalWrite(red, HIGH);
        digitalWrite(blue, LOW);
    }
   
}

larryd

else if (percentage > 33 & < 66) {

else if (percentage > 33 && percentage < 66) {
No technical PMs.
If you are asked a question, please respond with an answer.
If you are asked for more information, please supply it.
If you need clarification, ask for help.

rushy

Larry, thank you so much. I knew it was a school boy error I just couldn't see it, much appreciated :)

Go Up