Arduino UNO, FastLED Controlling 2 independent Addressable Strips

Hello all,

Im very new to programming Arduino boards, but Ive done it a few times with great success thanks to the fantastic portfolio of help and guides online, for that I thank you all!

So Im having a weird issue that Im not sure how to fix, I`ve been trying different solutions and nothing seems to work, maybe someone with more experience can help me with this.

This is my following schematic for controlling 2 individual Addressable LED Strips using WS2812B, 5VDC:

It`s pretty simple, LED Strip 1 keeps changing colors from White, Purple, and Blue, and if B2 is pushed, the A4 signal is High so Strip 1 stops changing colors and Strip 2 becomes RED, similarly if B1 is pushed, the A5 is now High so Strip 1 stops changing colors and Strip 2 becomes Green, fairly simple and works properly.

Here`s the program if someone needs to double-check:


#include <FastLED.h>
#define NUM_LEDS_1 44 //Number of LEDS in series
#define NUM_LEDS_2 56 //Number of LEDS in series 
#define DATA_PIN_1 2 //Main 44 LED STRIP
#define DATA_PIN_2 8 //LEDs 56x3 strips
#define COLOR_ORDER GRB //Just the color order so the numbers are in sequence Red, Green and Blue for the CHIPSET
#define CHIPSET WS2812B //CHIPSET of the LED STRIP
#define BRIGHTNESS 100 //Value can go from 1 to 255
#define VOLTS 5 //Strip is 5Volts only
#define MAX_AMPS 2200 //The PSU is limited by 2.2A

CRGB leds_1[NUM_LEDS_1]; //
CRGB leds_2[NUM_LEDS_2]; //


void setup() {
  // Code setup:
   delay (3000); //Small delay 
   pinMode(A4, INPUT_PULLUP); //This is a pullup input identification  
   pinMode(A5, INPUT_PULLUP); //This is a pullup input identification 
   FastLED.addLeds<CHIPSET, DATA_PIN_1, COLOR_ORDER>(leds_1, NUM_LEDS_1); //Just fastled needed informatives for LEDS_1
   FastLED.addLeds<CHIPSET, DATA_PIN_2, COLOR_ORDER>(leds_2, NUM_LEDS_2); //Just fastled needed informatives for LEDS_2
   FastLED.setMaxPowerInVoltsAndMilliamps (VOLTS, MAX_AMPS); //This is Max Volts and Amps call, limited by previously defined statements up top, AMPs before Brightness.
   FastLED.setBrightness(BRIGHTNESS); //Brightness adjustment, limited by previously defined statement up top.
   FastLED.clear(); //We clear any previous color of the strip, needed so the program starts from scratch
   FastLED.show(); //We show the new colors on the strip, needed so the program starts from scratch
  
}

void loop() {
  
    if(digitalRead(A5)){

     for (int i = 0; i<= NUM_LEDS_2; i++){
     leds_2[i] = CRGB (0,255,0);
     FastLED.show();
     delay(20);
    }
  }
  else{
  
     for (int i = -2; i <= NUM_LEDS_1
     ; i++) {
     leds_1[i] = CRGB (255, 255, 255);
     FastLED.show();
     delay(2);
     }
     for (int i = -2; i <= NUM_LEDS_1; i++) {
     leds_1[i] = CRGB (155, 0, 255);
     FastLED.show();
     delay(2);
    }
     for (int i = -2; i <= NUM_LEDS_1; i++) {
     leds_1[i] = CRGB (0, 0, 255);
     FastLED.show();
     delay(2);
    }
  }
  
  if(digitalRead(A4)){
   
     for (int i = NUM_LEDS_2; i>= 0; i--){
     leds_2[i] = CRGB (255,0,0);
     FastLED.show();
     delay(20);
     }
  }
  else{}
}

The issue that I`m having is related to a signal from LED Strip 1 also activating the first LED on LED Strip 2, so when LED Strip 1 is changing colors from White, Purple, and Blue, the LED Strip 2 first LED (just the very first one) also changes colors from White, Purple, and Blue.

I`ve tried changing the resistor size for LED Strip 2 but no luck, how can I prevent the first LED on Strip 2 to change colors like LED Strip 1?

arduino not powered?

Your code is accessing array indexes that are outside the arrays! That's why the first led of the second strip changes unexpectedly. You are lucky that the side-effect of your error is something so obvious. Normally when code access array indexes outside the array, the side effects are much more subtle and baffling.

Yup, you are correct, I did change the Array indexes and that did the trick, it`s working properly now, thank you so very much!

Thank you so very much Kolaha!
That also worked.

@kolaha 's code still has the array index bounds error in some (but not all) places in the code.

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