Hi, I am creating my first ever Arduino project with an Addressable LED strip.

Hi,
I am creating my first ever Arduino project with an Addressable LED strip. I am trying to create a waterfall type effect. So far it is working except that the reverse waterfall does not seem to work properly.

Issues:

  1. LED(0) does not remain lit
  2. LED(20) is supposed to light up in first loop iteration but it does on the second one.

Appreciate any help you can offer. Thanks.

Code that works:

void comedown () {
for (int dot2 = 0; dot2 <= NUM_LEDS; dot2++) {
for (int dot = NUM_LEDS; dot >= dot2; dot–) {

  leds[dot] = CRGB::Red;
  FastLED.show();
  delay(5);
  leds[dot] = CRGB::Black;
  FastLED.show();
  delay(5);
}
leds[dot2] = CRGB::Blue;
delay(5);

}
}

Code that does not work properly:

void goup () {

//Outer loop to turn and keep LEDs on
for (int dot2 = NUM_LEDS; dot2 >= 0; ) {

//Inner loop to waterfall dots  
for (int dot = 0; dot <= dot2; dot++) {

  leds[dot] = CRGB::Red;
  FastLED.show();
  delay(5);
  leds[dot] = CRGB::Black;
  FastLED.show();
  delay(5);
}

leds[dot2] = CRGB::Green;
delay(5);
dot2--;

}
}

change your for loop to for(int dot2 = NUM_LEDS - 1; dot2 >=0;) { – that should help a bit at least

Thank you Daniel. I tried that but unfortunately, that did not make any difference. Waterfall does start from LED(0) but green LED never comes back to LED(0) and stops at LED (1).

Actually all your NUM_LEDS - the way that you’re using them need to be NUM_LEDS-1 - otherwise you will write to leds[NUM_LEDS] - which will write outside the LEDs array which can cause random problems. for more help - please upload your entire sketch to http://gist.githhub.com and link to it here so we can see the entirety of what you’re doing and trying.

Hi, here is a link to the complete file. Thanks again for your help. I understand the concept of going out of array bounds but can’t tell why it would work one way but not the other. I would think that if it was NUM-LEDS-1 issue then whole thing would work until 19 LEDs rather than 20. In this case part of it is working on all 20 while other is only until 19.

So, on the first run through the outer loop in group the value of dot2 is 19, and you’re going to make leds[0] red, and then black all the way up to leds[19] (which is the 20th led - there is no leds[20] – that value exists outside of your array). After that loop, you will then set leds[19] to green, and then go through a second time. Now the value of dot2 is 18 and you’re going to make leds 0 to 18 red, and then black alternatingly, and finally make leds[18] green, and so on down the line, right? And then eventually, dot2 will be 0, and your inter loop will set leds[0] to red, then leds[0] to black, and then on exiting that loop, leds[0] will be set to Green. Is that not what you are seeing – but your are setting leds[0] to black on every run of your inner loop.

As for why you weren’t seeing seeing leds[20] light up on the first iteration - that’s because leds[20] doesn’t exist - so you were writing to an led that doesn’t exist, and it wasn’t until your second iteration that you were lighting up leds[19] to green, which is the 20th led, which is why you didn’t see it until your second iteration - this is what i had you fix by making it NUM_LEDS - 1.

Hi Daniel,

Thank you for all your help. NUM_LEDS-1 wasn’t working but then I noticed your comment that inner loop is turning LEDs off. Outer loop is changing the color to green but not turning it on. A simple show command in the outer loop turned it on and fixed everything. :smiley: Thanks again.