FastLED without delay()

Hello all,

I'm trying to light my LED strip while running another program, unfortunately the example below uses the delay() function which is interrupting my other program.

#include <FastLED.h>
#define LED_PIN 22
#define NUM_LEDS 8
CRGB leds[NUM_LEDS];
void setup() {
FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
}
void loop() {
for (int i = 0; i < NUM_LEDS; i++) {
leds = CRGB ( 0, 0, 255);

  • FastLED.show();*
  • delay(15);*
  • }*
  • for (int i = NUM_LEDS; i >= 0; i--) {*
    _ leds = CRGB ( 255, 0, 0);_
    * FastLED.show();*
    * delay(15);*
    * }*
    }
    led_strip.ino (401 Bytes)

The demo Several Things at a Time illustrates the use of millis() to manage timing without blocking. It may help with understanding the technique.

Note how each function runs very briefly and returns to loop() so the next one can be called. None of the functions tries to complete a task in one call. And there may be dozens of calls to a function before it is actually time for it to do anything.

Have a look at Using millis() for timing. A beginners guide if you need more explanation.

...R

"the example below uses the delay() function which is interrupting my other program."

If the other program uses delay(), or other blocking code, then that will mess things up too.