Single line leds code in Arduino fastLED

Hi ,

Can someone plz help me with an alternate single line code instead of multiple leds lines in fastLED program as given in attached code. All LEDs should be simultaneously blink and not sequentially…

Thanks


     leds[0] = CRGB(255,0,0);
     leds[1] = CRGB(255,0,0);
     leds[2] = CRGB(255,0,0);
     leds[3] = CRGB(0,255,0);
     leds[4] = CRGB(0,255,0);
     leds[5] = CRGB(0,255,0);
     leds[6] = CRGB(0,0,255); 
     leds[7] = CRGB(0,0,255);
     leds[8] = CRGB(0,0,255);

     FastLED.show();
     delay(200);
      
   
 
      leds[0] = CRGB(0,0,0);
      leds[1] = CRGB(0,0,0); 
      leds[2] = CRGB(0,0,0);
      leds[3] = CRGB(0,0,0);
      leds[4] = CRGB(0,0,0);
      leds[5] = CRGB(0,0,0);
      leds[6] = CRGB(0,0,0); 
      leds[7] = CRGB(0,0,0);
      leds[8] = CRGB(0,0,0);
        
     
     FastLED.show();
     delay(200);

for ( uint8_t i = 0; i < 9; i++ ) leds[i] = CRGB( i < 3 ? 255 : 0, i >= 3 && i < 6 ? 255 : 0, i >= 6 ? 255 : 0 );

But why ? It won't make your code faster, and probably not smaller (when compiled)

@guix

leds[7] is missing a closing bracket.
You forgot to code that :slight_smile:
Leo..

1 Like
leds[0] = CRGB(255,0,0); leds[1] = CRGB(255,0,0); leds[2] = CRGB(255,0,0); leds[3] = CRGB(0,255,0); leds[4] = CRGB(0,255,0); leds[5] = CRGB(0,255,0); leds[6] = CRGB(0,0,255); leds[7] = CRGB(0,0,255; leds[8] = CRGB(0,0,255);

Sorry … missed to add that I want all LEDs to be simultaneously glow and not sequentially ….

Because I want to add multiple patterns in one loop and when call out from the loop using attachinterupt , it compltes the loop and then exits which delays other followed funtion ….hence wants to minimise or optimize the code for faster callout/interrupt..

Why would you want to use an interrupt? :astonished:

You can declare the CRGB values in a constant array, and use memcpy() to move them in one line, to leds[]. For the zero values, you can clear the array with memset().

None of the suggestions so far, have involved any sequential activity. So I have no idea why you're talking about that.

All the array assignments are performed invisibly, it is only when show() is called, that the LEDs change state.

Thus it is futile to try to speed them up.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.