Simple Led strip with array issue

I am trying to do a simple code, and I am sure my issue is staring me right in the face but... I have an LED strip with 6 LED's. Trying to get them to light up in a certain order, being 1st led with 3rd, 2nd with 4th, 3rd with 5th.

So I create 3 arrays, butting the 2 leds in each. Everything cycles through just fine. However the first led, "leds[0]" stays lit no matter what I do. I have tried fastled.clear, I have tried just setting it to (0,0,0) but no matter what, that first led on the strip doesn't turn off like the rest do.

#include "FastLED.h"
#include <EEPROM.h>
#define NUM_LEDS 6
CRGB leds[NUM_LEDS];
#define DATA_PIN 6


int Arry1[NUM_LEDS] = {0, 3};
int Arry2[NUM_LEDS] = {1, 4};
int Arry3[NUM_LEDS] = {2, 5};
int i = 0;

void setup()
{
  FastLED.addLeds<WS2811, DATA_PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
  FastLED.clear();
}
  
void loop(){
   FastLED.clear();
   delay(500);
   Ary1();

   delay(500);
   Ary2();

   delay(500);
   Ary3();
  }

 void Ary1(){
    FastLED.clear();
  for(int i = 0; i < NUM_LEDS; i++){
    leds[Arry1[i]] = CRGB::Red; 
    FastLED.show();
 }
 }

void Ary2(){
  FastLED.clear();
  for(int i = 0; i < NUM_LEDS; i++){
    leds[Arry2[i]] = CRGB::Red; 
    FastLED.show();
 }
}
 
 void Ary3(){
   FastLED.clear();
  for(int i = 0; i < NUM_LEDS; i++){
    leds[Arry3[i]] = CRGB::Red; 
    FastLED.show();
 }
 }

Run this code and you will find out why :slight_smile:

int Arry1[NUM_LEDS] = {0, 3}; // <- this is same as {0, 3, 0, 0, 0, 0} in your case.
for(int i = 0; i < NUM_LEDS; i++){
    Serial.printf(Arry1[i]); 
}

//this should work
for(int i = 0; i < 2; i++){
    Serial.printf(Arry1[i]); 
}

Even changing it to....

 void Ary1(){
    FastLED.clear();
  for(int i = 0; i < 2; i++){
    leds[Arry1[i]] = CRGB::Red; 
     Serial.println(Arry1[i]); 
    FastLED.show();
 }
 }

It still produces the same results with that first led on the strip always being lit up.

The monitor shows...
17:07:04.011 -> 0
17:07:04.011 -> 3
17:07:05.561 -> 0
17:07:05.561 -> 3
17:07:07.056 -> 0
17:07:07.056 -> 3
17:07:08.608 -> 0
17:07:08.608 -> 3
17:07:10.105 -> 0

If I serialprint all of the arrays I get this...

17:08:02.696 -> 0
17:08:02.696 -> 3
17:08:03.211 -> 1
17:08:03.211 -> 4
17:08:03.211 -> 0
17:08:03.211 -> 0
17:08:03.726 -> 2
17:08:03.726 -> 5
17:08:03.726 -> 0
17:08:03.726 -> 0
17:08:03.726 -> 0
17:08:03.726 -> 0
17:08:04.195 -> 0
17:08:04.195 -> 3

An image please of your setup.

LED0 not turn off. In your troubleshooting when you went back to see if the simple example would work, did LED0 do the proper thing?

No it did not work with the code you supplied. I am not sure what you mean by image of the setup, it's literally just an arduno nano, with an LED strip cut down to 6 led's. Ground to ground, power to 5v, digital to pin 6.

Here is the code I updated...

#include "FastLED.h"
#include <EEPROM.h>
#define NUM_LEDS 6
CRGB leds[NUM_LEDS];
#define DATA_PIN 6


int Arry1[NUM_LEDS] = {0, 3};
int Arry2[NUM_LEDS] = {1, 4};
int Arry3[NUM_LEDS] = {2, 5};
int i = 0;


void setup()
{
  FastLED.addLeds<WS2811, DATA_PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
  FastLED.clear();
  Serial.begin(9600);
}
  
void loop(){

   FastLED.clear();
   delay(500);
   Ary1();

   delay(500);
   Ary2();

   delay(500);
   Ary3();
  }

 void Ary1(){
    FastLED.clear();
  for(int i = 0; i < 2; i++){
    leds[Arry1[i]] = CRGB::Red; 
     Serial.println(Arry1[i]); 
    FastLED.show();
 }
 }

void Ary2(){
  FastLED.clear();
  for(int i = 0; i < 4; i++){
    leds[Arry2[i]] = CRGB::Red; 
   Serial.println(Arry2[i]); 
    FastLED.show();
 }
}
 
 void Ary3(){
   FastLED.clear();
  for(int i = 0; i < 6; i++){
    leds[Arry3[i]] = CRGB::Red; 
  Serial.println(Arry3[i]); 
    FastLED.show();
 }
 }

You are saying that when you tried the examples for the led strip library LED0 did not work either? If this is the case the issue is not with your code. Thus, if you could take a picture of your setup and post it, the image may prove useful.

the clear function doesn't clear the array unless if you pass in a true parameter. try:

FastLED.clear(true); // this will erase the whole leds array.	

for(int i = 0; i < 2; i++) //for all three Ary function

or you can try the following code (might be buggy, didn't compile it)

#include "FastLED.h"
#include <EEPROM.h>
#define NUM_LEDS 6
CRGB leds[NUM_LEDS];
#define DATA_PIN 6

int Arry1[] = {0, 3}; //you can delare more led to light up, for example: int Arry1[] = {0, 3, 5};
int Arry2[] = {1, 4};
int Arry3[] = {2, 5};

void setup()
{
  FastLED.addLeds<WS2811, DATA_PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
}
  
void loop(){
   delay(500);
   updateLed(Arry1, sizeof(Arry1), CRGB::Red);

   delay(500);
   updateLed(Arry2, sizeof(Arry2), CRGB::Red);

   delay(500);
   updateLed(Arry3, sizeof(Arry3), CRGB::Red);
 }

 void updateLed(int x[], int arraySize, CRGB color){
    FastLED.clear(true);
    for(int i = 0; i < arraySize; i++){
        leds[x[i]] = color; 
    }
    FastLED.show();
 }
 

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