Addressing multiple LED strips simultaneously for a light show

Hi folks,

I am trying to build a LED strip setup to create a light show for music. I have read some articles on the forum to get basic ideas to implement this project. Furthermore, I intend to manually program which LED (strip) show at which time.

My question is, how can I address each LED strip individually without making the other strips wait during the necessary delay?

The code below makes the first strip glow red for 1 s with increasing brightness. Then the second strip starts to glow for 1 s with increasing brightness. This code works on my hardware (Mega2560 and NeoPixels).

For example, how can I make the second strip start to glow after 0.5 s (during the first glow). In my opinion, I would have to somehow cut the first loops. Is there a better way to do this?

I hope I didn't miss a similar question in the forum!

Thanks in advance! :slight_smile:

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif
#define PIN6        6
#define PIN7        7
#define NUMPIXELS 5

Adafruit_NeoPixel strip1(NUMPIXELS, PIN6, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip2(NUMPIXELS, PIN7, NEO_GRB + NEO_KHZ800);

void setup() {
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
  clock_prescale_set(clock_div_1);
#endif

  strip1.begin();
  strip2.begin();
}

void loop() {
  
  strip1.clear();
  strip2.clear();

  for(int i=0; i<50; i++) {
    for(int j=0; j<NUMPIXELS; j++) {
      strip1.setPixelColor(j, strip1.Color(i, 0, 0));
    }
  strip1.show();
  delay(20);
  }

  delay(500);
  strip1.clear();
  strip1.show();
  delay(500);

  for(int i=0; i<50; i++) {
    for(int j=0; j<NUMPIXELS; j++) {
      strip2.setPixelColor(j, strip2.Color(i, 0, 0));
    }
  strip2.show();
  delay(20);
  }

  delay(500);
  strip2.clear();
  strip2.show();
  delay(500);
  
}

Do not use delay(). Use millis() or micros() for timing as shown in these tutorials.
Blink without delay().
Beginner's guide to millis().
Several things at a time.

Don't use for loops (or while loops). They block execution. Do stuff a step at a time instead of all at once. The tutorials help to show how.

Thanks for pointing me there! :slight_smile:
I will mark this as the answer and read those tutorials.

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