Boolean If/Else


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);

void loop() {
  if (condition){
    for (int i = 0; i <= 59; i++){
      leds[i] = CRGB(red,0,0);}
    red += 1;
    if (red > 249){
      condition = false;}}
    for (int i = 0; i <= 59; i--){
      leds[i] = CRGB(red,0,0);}
    red -= 1;
    if (red < 1){
      condition = true;}}

That code doesn't compile.


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.



Don't you just hate it when that happens?