0

I want to make a strip led application(Fade In/Fade Out).Each strip has 48 pixels.One of the strips should be red and the other should be blue.Using the for loop, I managed to fade in-fade out a small number of strips (eg 10).But when I fade in / fade out all of the 48 leds, the code behaves as if there is a "delay".I guess that's because there's a lot of data in the for loop.Is there a way to do fade in / fade out without using a for loop?

#include "FastLED.h"
#define NUM_LEDS_PER_STRIP 48
CRGB redLeds[NUM_LEDS_PER_STRIP];
CRGB blueLeds[NUM_LEDS_PER_STRIP];
void setup() {
FastLED.addLeds<NEOPIXEL, 6>(redLeds, NUM_LEDS_PER_STRIP);
FastLED.addLeds<NEOPIXEL, 7>(blueLeds, NUM_LEDS_PER_STRIP);
FastLED.setBrightness(0); 
}

void loop() {
//fade in
for(int i=0;i<256;i=i+5) {
for(int j=0;j<NUM_LEDS_PER_STRIP;j++) {
FastLED.setBrightness(i); 
redLeds[j] = CRGB(255,0,0); 
blueLeds[j] = CRGB(0,0,255); 
FastLED.show(); 
}}
//fade out
for(int i=255;i>=0;i=i-5) {
for(int j=0;j<NUM_LEDS_PER_STRIP;j++) {
FastLED.setBrightness(i);  
redLeds[j] = CRGB(255,0,0); 
blueLeds[j] = CRGB(0,0,255); 
FastLED.show(); 
}}
}

2 Answers 2

1

Each change of brightness requires sending out 48 LEDs x 3 bytes/strip, = 144 bytes = 1152 bits of data. Each bit needs 2.5uS of data, so 2.88mS minimum at 400 KHz data rate. I don't know what rate FastLED.h uses, might be as fast as 800 KHz. How many strips? 2? So double that.

Each string needs all of its data sent out if any one LED changes, so you might change 1 LED, and leave 143 alone, all the data still gets sent out. That's just the way the addressable strips work.

3
  • Thank you for the advice, but I don't know what you mean by "leave 143 alone."How do I make the 143 LED leave alone with the code?
    – bopele
    Commented Jul 29, 2019 at 16:16
  • @bopole 143: the number of bytes for one ledstrep that you do NOT want to change (48 leds * 3 bytes/strip = 144 bytes, 1 you want to change, the others (143) not). Commented Jul 29, 2019 at 16:18
  • Say you had just 1 LED. Now you want to change 1 LED, and leave the other 2 as is. You have to send the 1 new value, and resend the 2 unchanged values. That's the way a chip like WS2812B and others used in addressable strips work. Expand to 48 LEDs. One byte changes, you send that new value and resend the unchanged values for everything else.
    – CrossRoads
    Commented Jul 29, 2019 at 16:20
0

CrossRoads already gave a likely reason for the delay (so upvoted).

One way to solve it is using one microcontroller (slave) per LED string and split the load, and using one microcontroller as master:

  • Use a fast communication protocol between your current MCU (master) and the slaves (preferably small/cheap ones like Arduino Mini/Micro's), e.g. SPI which is easy to use for communication.
  • To make sure they all start at the same time, you can first send all data (SPI), and at the end after all data is sent to all slaves, set on the master a GPIO high where all slaves listen to, knowing they have to start sending.
  • SPI is very fast, but if you want to save communication time, you can make some smart commands (e.g. like sending a command to reset a group of bytes, or change a group of bytes by a certain value etc). Depending on what commands you want, it might be needed to store the data of all led strips on your Arduino, which can cost quite some money (see CrossRoads answer).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.