LEDs still on when told to go off

Hey, I have yet another question. For whatever reason, the LEDs are still on when not supposed to, even though I’m clearly telling them to turn off.

What am I doing wrong?
Arduino Code:

#include <Servo.h>
Servo myServo;

int const redLEDPin = 9;
int const yellowLEDPin = 10;
int const greenLEDPin = 11;

int const redPotPin = A3;
int const yellowPotPin = A2;
int const greenPotPin = A1;

int currentColorValueRed;
int currentColorValueYellow;
int currentColorValueGreen;

int const potPin = A0;
int potVal;
int angle;

void setup():

void setup() {
  myServo.attach(6);
  
  Serial.begin(9600);
  
  pinMode(redLEDPin, OUTPUT);
  pinMode(yellowLEDPin, OUTPUT);
  pinMode(greenLEDPin, OUTPUT);
  
  currentColorValueRed = (255 - map( analogRead(redPotPin), 0, 1024, 0, 225));
  currentColorValueYellow = (255 - map( analogRead(yellowPotPin), 0, 1024, 0, 225));
  currentColorValueGreen = (225 - map( analogRead(greenPotPin), 0, 1024, 0, 225));
  
  analogWrite(redLEDPin, currentColorValueRed);
  analogWrite(yellowLEDPin, currentColorValueYellow);
  analogWrite(greenLEDPin, currentColorValueGreen);
  
}

void loop()

void loop() {
  potVal = analogRead(potPin);
  Serial.print("potVal: ");
  Serial.print(potVal);
  
  angle = map(potVal, 0, 1023, 0, 179);
  Serial.print("angle: ");
  Serial.println(angle);
  
  
  if(angle < (59)){
    delay(15);
    digitalWrite(redLEDPin, LOW);
    digitalWrite(yellowLEDPin, LOW);
    digitalWrite(greenLEDPin, HIGH);
    
  }else if(angle >(60) && angle < (64)){
    for(int pinNumber = 9; pinNumber<12; pinNumber ++){
      digitalWrite(pinNumber, LOW);
    }
    
  }else if(angle > (64) && angle < (120)){
    delay(15);
    digitalWrite(redLEDPin, LOW);
    digitalWrite(yellowLEDPin, HIGH);
    digitalWrite(greenLEDPin, LOW);
    
  }else if(angle >(120) && angle <(125)){
    for(int pinNumber = 9; pinNumber <12; pinNumber ++){
      digitalWrite(pinNumber, LOW);
      
    }
    
  }else if(angle > (125)){
    delay(15);
    digitalWrite(redLEDPin, HIGH);
    digitalWrite(yellowLEDPin, LOW);
    digitalWrite(greenLEDPin, LOW);
  }
  
  myServo.write(angle);
  delay(15);
}

What happens when angle is exactly equal to 60, or 64, or 120?

econjack:
What happens when angle is exactly equal to 60, or 64, or 120?

Well, I incorrectly spaced the numbers. I changed them to this:

if(angle < (61)){
    delay(15);
    digitalWrite(redLEDPin, LOW);
    digitalWrite(yellowLEDPin, LOW);
    digitalWrite(greenLEDPin, HIGH);
    
  }else if(angle >(60) && angle < (64)){
    for(int pinNumber = 9; pinNumber<12; pinNumber ++){
      digitalWrite(pinNumber, LOW);
    }
    
  }else if(angle > (63) && angle < (120)){
    delay(15);
    digitalWrite(redLEDPin, LOW);
    digitalWrite(yellowLEDPin, HIGH);
    digitalWrite(greenLEDPin, LOW);
    
  }else if(angle >(119) && angle <(125)){
    for(int pinNumber = 9; pinNumber <12; pinNumber ++){
      digitalWrite(pinNumber, LOW);
     
    }
    
  }else if(angle > (125)){
    delay(15);
    digitalWrite(redLEDPin, HIGH);
    digitalWrite(yellowLEDPin, LOW);
    digitalWrite(greenLEDPin, LOW);
  }

But still. For example, at angle 121, all three LEDs turn on…

Is there something wrong with the serial monitor? Should I add a larger delay (if so where), so the Arduino has more time to process the information correctly? Or is there just a fault in the code somewhere?

}else if(angle >(60) && angle < (64)){
for(int pinNumber = 9; pinNumber<12; pinNumber ++){
digitalWrite(pinNumber, LOW);
}

}else if(angle > (63) && angle < (120)){

Looks like extra } in there.

steinie44:

}else if(angle >(60) && angle < (64)){
for(int pinNumber = 9; pinNumber<12; pinNumber ++){
digitalWrite(pinNumber, LOW);
}

}else if(angle > (63) && angle < (120)){

Looks like extra } in there.

No, there’s a { on the first and second line of what you quoted.

Are the leds always on or do they come on when you want just not off?

Why are your analogReads of the led brightness pots called in set up are they just like trim pots or something that dosnt get adjusted?

Also i dont think you need any more delays you may be able to do with out the ones there now unless your servo needs it for some reason.

What's with the parenthesis around the values?
Also, I would make pinNumber a global variable, since it's defined twice.

Your code in setup() suggests a common anode configuration for the LEDs - is that correct?

Should I add a larger delay (if so where), so the Arduino has more time to process the information correctly?

How do you think that will work?

A delay uses all the processors resource counting, it does not free time to do anything else. This is a processor not a person, you don't give it extra time to think by giving it something to think about.

If your LEDs do not appear to be turning off then you are probably turning them on again, just after you turn them off.