fastled

hi i was playing with the fastled multiarrays instead of just 1 led i tried to get 4 leds so i altered 2 lines now i can gets 4 to light one way but it stops the the program the other way can anyone please help

i put the sketch as an attachment i dont no if this is how you do it
thank you

arch_test_1.ino (1.76 KB)

mel:
i put the sketch as an attachment i dont no if this is how you do it

If you want help from people on mobile devices, it isn't.

redLeds[i-4] = CRGB::Black; And when i == zero?

Here's the OP's code:

// MultiArrays - see https://github.com/FastLED/FastLED/wiki/Multiple-Controller-Examples for more info on
// using multiple controllers.  In this example, we're going to set up three NEOPIXEL strips on three
// different pins, each strip getting its own CRGB array to be played with

#include "FastLED.h"

#define NUM_LEDS_PER_STRIP 60
CRGB redLeds[NUM_LEDS_PER_STRIP];
CRGB greenLeds[NUM_LEDS_PER_STRIP];
CRGB blueLeds[NUM_LEDS_PER_STRIP];

// For mirroring strips, all the "special" stuff happens just in setup.  We
// just addLeds multiple times, once for each strip
void setup() {
  // tell FastLED there's 60 NEOPIXEL leds on pin 10
  FastLED.addLeds<NEOPIXEL, 10>(redLeds, NUM_LEDS_PER_STRIP);

  // tell FastLED there's 60 NEOPIXEL leds on pin 11
  FastLED.addLeds<NEOPIXEL, 11>(greenLeds, NUM_LEDS_PER_STRIP);

  // tell FastLED there's 60 NEOPIXEL leds on pin 12
  FastLED.addLeds<NEOPIXEL, 12>(blueLeds, NUM_LEDS_PER_STRIP);

}

void loop() {
  for(int i = 0; i < NUM_LEDS_PER_STRIP; i++) {
    // set our current dot to red, green, and blue
    redLeds[i] = CRGB::Red;
    greenLeds[i] = CRGB::Green;
    blueLeds[i] = CRGB::Blue;
    FastLED.show();
    // clear our current dot before we move on
    redLeds[i-4] = CRGB::Black;//this will have 4 leds lit before it blacks out//
    greenLeds[i] = CRGB::Black;
    blueLeds[i] = CRGB::Blue;
    delay(50);
  }

  for(int i = NUM_LEDS_PER_STRIP-1; i >= 0; i--) {
    // set our current dot to red, green, and blue
    redLeds[i] = CRGB::Red;
    greenLeds[i] = CRGB::Green;
    blueLeds[i] = CRGB::Blue;
    FastLED.show();
    // clear our current dot before we move on
    redLeds[i+4] = CRGB::Black;  //this should do it in reverse but it stops working //
    greenLeds[i] = CRGB::Black;
    blueLeds[i] = CRGB::Blue;
    delay(50);
  }
}

ok i-4 works well one way as 4 leds lit but when i add the i+4 on the return it stops if i take the +4 out it works as a single led
sorry i dont no how to post for mobiles im on a pc
thanks

ok i-4 works well one way as 4 leds lit but when i add the i+4 on the return it stops if i take the +4 out it works as a single led

I really do not understand this reply. What AWOL was trying to point out is that YOU need to take steps to assure that the value in the brackets is valid.

If you have [i-4], and i is 0, then the value is -4, which is NOT a valid value.

It would appear that you don't want to do anything if i is less than 4, so

if(i >= 4)
   redLeds[i-4] = CRGB::Black;

ok i thought i was 50 as it counted up to the 50 leds in the string and then it would count down from 50 as it does in the original script and by adding the 4 it would count 4 behind i and trail 4 leds insted of 1 led
it works on the way up but not in revers
sorry if im misunderstanding

it works on the way up but not in revers

As written, you got lucky that writing outside the bounds of the array did not appear to cause problems. When working down from 59, you write to positions 63, 62, 61, and 60 of your array that has positions from 0 to 59.

Writing outside the bounds of an array is NEVER a good idea. Defensive programming IS.

ok i got it i have 50 led in strip so i went to 54 i then put in

if(i <= 50)
redLeds[i+4] = CRGB::Black;

and now it works 4 leds on both ways thanks for that info