kitesurfer1404 / WS2812FX

WS2812 FX Library for Arduino and ESP8266
MIT License
1.6k stars 347 forks source link

Can't add 2nd instance. (Running multiple LED-strips via different pins at once) #323

Closed TipsTricksMore closed 1 year ago

TipsTricksMore commented 1 year ago

Hi @kitesurfer1404 thanks for this great lib! It's awesome.

I'm running two LED sources (WS2812B) via two different pins on my Arduino Nano. When running the "auto-mode-example" on each of them individually, everything is fine. However, when I'm adding a 2nd instance to drive both of them at the same time, nothing happens...

This is my basic code. Is this a bug, or am I missing something?

#include <WS2812FX.h>

#define LED_COUNT 256
#define LED_PIN 3

#define LED_COUNT2 9
#define LED_PIN2 10

#define TIMER_MS 5000

// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
//   NEO_RGBW    Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
WS2812FX ws2812fx1 = WS2812FX(LED_COUNT, LED_PIN, NEO_RGB + NEO_KHZ800);
WS2812FX ws2812fx2 = WS2812FX(LED_COUNT2, LED_PIN2, NEO_RGB + NEO_KHZ800);

unsigned long last_change = 0;
unsigned long now = 0;

void setup() {
  ws2812fx1.init();
  ws2812fx1.setBrightness(100);
  ws2812fx1.setSpeed(1000);
  ws2812fx1.setColor(0x007BFF);
  ws2812fx1.setMode(FX_MODE_STATIC);
  ws2812fx1.start();

  ws2812fx2.init();
  ws2812fx2.setBrightness(100);
  ws2812fx2.setSpeed(1000);
  ws2812fx2.setColor(0x007BFF);
  ws2812fx2.setMode(FX_MODE_STATIC);
  ws2812fx2.start();

}

void loop() {
  now = millis();

  ws2812fx1.service();
  ws2812fx2.service();

  if(now - last_change > TIMER_MS) {
    ws2812fx1.setMode((ws2812fx1.getMode() + 1) % ws2812fx1.getModeCount());
    ws2812fx2.setMode((ws2812fx2.getMode() + 1) % ws2812fx2.getModeCount());
    last_change = now;
  }
}

Help would be very much appreciated. Thanks a lot!

BR Leo

TipsTricksMore commented 1 year ago

Oh, I just stumbled across this... https://github.com/kitesurfer1404/WS2812FX/issues/273#issue-775982516 So it's a RAM problem. I'll switch to a ESP32 then.. Thanks.