Boolean If/Else

Hi,

Looking for some help as to why my else statement will not run. I'm relatively new to Arduino, but I can't seem to figure out why this logic won't work. The loop just keeps referring to the first if statement and never switches over to the else statement even when condition = false. With some debugging print statements in the serial monitor I found out the condition resorts back to true somehow. For some context, I am trying to do some initial tests on an LED strip using the FastLED library. Any help would be greatly appreciated!

int red = 0;
bool condition = true;

void setup() { 
      FastLED.addLeds<WS2812, DATA_PIN, RGB>(leds, NUM_LEDS);
      Serial.begin(9600);
}

void loop() {
  if (condition){
    for (int i = 0; i <= 59; i++){
      leds[i] = CRGB(red,0,0);}
    red += 1;
    if (red > 249){
      condition = false;}}
      
  else{
    for (int i = 0; i <= 59; i--){
      leds[i] = CRGB(red,0,0);}
    red -= 1;
    if (red < 1){
      condition = true;}}
      
  Serial.println(condition);
  Serial.println(red);
  FastLED.show();
  delay(40);
}

That code doesn't compile.

Pete

Figured it out, the problem was in the for loop associated with the else statement not any logic based error. I can't figure out how to delete a post though

You don't delete a post. You explain what caused your problem so that others can benefit.

Pete

;}}

Don't you just hate it when that happens?