Driving 2 separate WS2812 on a single Arduino?

#include <FastLED.h>

#define NUM_LEDS 5       /* The amount of pixels/leds you have */
#define DATA_PIN_A 3     /* The pin your data line is connected to */
#define DATA_PIN_B 4
#define LED_TYPE WS2812B /* I assume you have WS2812B leds, if not just change it to whatever you have */
#define BRIGHTNESS 255   /* Control the brightness of your leds */
#define SATURATION 127   /* Control the saturation of your leds */

CRGB leds[NUM_LEDS];

void setup() {
  pinMode (2, INPUT);      /* high for color cycling, low for fixed colors */
  FastLED.addLeds<LED_TYPE, DATA_PIN_A>(leds, NUM_LEDS);
  FastLED.addLeds<LED_TYPE, DATA_PIN_B>(leds, NUM_LEDS);
}

void loop() {
  while (digitalRead(2)); {
    for (int j = 0; j < 255; j++) {
      for (int i = 0; i < NUM_LEDS; i++) {
        leds[i] = CHSV(i - (j * 2), BRIGHTNESS, SATURATION); /* The higher the value 4 the less fade there is and vice versa */

      }
      FastLED.show();
      delay(30); /* Change this to your hearts desire, the lower the value the faster your colors move (and vice versa) */
    }
    // blue to DATA_PIN_A
    // yellow to DATA_PIN_B 
    while (!digitalRead(2)); {  //basically stop loop until pin 2 is back high
    }
  }
}

Rough code. It works but I was hoping someone could explain how to:
drive LEDs on DATA_PIN_B at a different color (say, 180° from those on A)
and to set A to blue and B to yellow when pin 2 is low.

You only have one array to hold the colours of the LEDs, so right now they can't be different colours.

Is that the limitation of fastled library or can someone explain how to do multi led strips?

The alternative are the dumb RGB LEDs, it wouldn't have color gradient (red one end to orange other end for example) but I'd be able to control both strips independently. 6 PWM pins and 6 MOSFETs total though.

Declare a separate array for the other strip.

CRGB leds[NUM_LEDS];
CRGB moreLeds[NUM_LEDS] // assuming same number

void setup() {
  pinMode (2, INPUT);      /* high for color cycling, low for fixed colors */
  FastLED.addLeds<LED_TYPE, DATA_PIN_A>(leds, NUM_LEDS);
  FastLED.addLeds<LED_TYPE, DATA_PIN_B>(moreLeds, NUM_LEDS);

Access the second strip the same way of the first but use the moreLeds[] array. The second strip is independent of the first.

No, in post #2 I was trying to convey that the limitation is entirely within your code and suggesting that this can be fixed. @groundFungus has given a more explicit suggestion about how to do that.

Ah I see!! TY!

Final code in case anyone comes across this via searches:

#include <FastLED.h>

#define NUM_LEDS 5       /* The amount of pixels/leds you have, both strips should have the same number for simplicity */
#define DATA_PIN_A 3     /* The pin your data line for first strip is connected to */
#define DATA_PIN_B 4    /* second data line for second strip */
#define LED_TYPE WS2812B /* I assume you have WS2812B leds, if not just change it to whatever you have */
#define BRIGHTNESS 255   /* Control the brightness of your leds */
#define SATURATION 127   /* Control the saturation of your leds */


CRGB leds[NUM_LEDS];
CRGB moreLeds[NUM_LEDS];

void setup() {
  pinMode (2, INPUT);         /* high for color cycling, low for fixed colors */
  pinMode(2, INPUT_PULLUP);
  FastLED.addLeds<LED_TYPE, DATA_PIN_A>(leds, NUM_LEDS);
  FastLED.addLeds<LED_TYPE, DATA_PIN_B>(moreLeds, NUM_LEDS);
}

void loop() {
  if (digitalRead(2)) {
    while (digitalRead(2)) {
      for (int j = 0; j < 255; j++) {
        for (int i = 0; i < NUM_LEDS; i++) {
          leds[i] = CHSV(i - (j * 3), BRIGHTNESS, SATURATION);
          moreLeds[i] = CHSV(i - ((48 + j) * 3), BRIGHTNESS, SATURATION);
        }
        FastLED.show();
        delay(30); /* Change this to your hearts desire, the lower the value the faster your colors move (and vice versa) */
      }
    }
  } else {
    for (int i = 0; i < NUM_LEDS; i++) {
      leds[i] = CRGB(0, 0, 255);
      moreLeds[i] = CRGB(255, 255, 0);
      FastLED.show();
    }
    while (!digitalRead(2)); {
    } /* do nothing here while pin 2 is low. Basically twiddle thumbs at 16 million times a second */
  }
}

I added ((48 + j)) to moreLeds to force the second one to have offset color. It will need to be adjusted if someone changes the hue speed multiplier from 3, I haven't quite got the math down yet.

And when pin 2 goes low, at the end of color cycling (which takes 255 steps in j loop), the color stops at yellow and blue and just twiddles thump until pin 2 goes high.

If anyone was wondering what I was going to do with this, I was going to make 2 layer of CNC engraved acrylic sheets, one strip illuminate one sheet via edge, and second one for second edge. The whole project will run off USB since my PC provides continuous power even when sleeping or shut down (unless I physically turn off power supply or unplug it). The digital pin 2 will be connected to some random +5v line like power cable for SATA drive since it does go off when the computer sleeps or shut downs.

When it's running, the 2 sheets will be cycling through colors and when it's shut down, it'll be static blue and yellow. I'll probably adjust the brightness if it's too bright.

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