Hi, I'm having an incredibly strange problem where a few of my functions completely

Hi, I’m having an incredibly strange problem where a few of my functions completely break my code for some reason.

I’ve pasted the sketch into a pastebin link for reference.

For some reason whenever I enter modes 16,17, or 18, leds[0] and leds[1] essentially stop functioning for the remainder of the program’s run. The leds will change in some modes, refuse to change in others and just cause my functions to stop working properly.

I’ve tried cycling through every other mode to recreate the problem and it only seems to occur after I enter those modes. The modes each do the same thing with just different colors.

I checked to see if it was the data line of the strip by making a different strip the first data line in the series and I got the same results on the new strip, the first two LEDS became finicky.

If anyone can spot an error or offer up some suggestions I would appreciate it. I apologize in advance for the length of the code.

Do you have a 300-500 ohm resistor on the LED’s data line?

I do I have a 500 ohm resistor between the last strips data line and ground, Although I’m not sure why.

edit: It was a 20kohm resistor that Michael Sharnet recommended the last time I posted here.

It should be on the INPUT side of the data, toward the beginning of the LED’s. Google for Adafruit Neopixel Uber guide

Ah my mistake, I’ve added 2 200 ohm resistors in series to the input side, the problem still remains. Although it seems to cause less severe of a bug.

If you look closely at any prefabricated strip, you’ll notice series resistors every half a meter. So if it’s a 32 pixel/meter strip, there will be a resistor at the beginning and one between pixels 16 and 17. For the 48px/m ones, it’s every 24 pixels. So you have 600 LEDs, start adding resistors, at the very least every 100 pixels and see what happens. You may need to go even less between them. Also, at the end of the line, pull the data lines down to avoid reflection. 47-100 Ohm should do the trick.

I’m using prefabricated strips and I do see resistors on them. Maybe I should have specified. I have 10 60 LED strips.

You’re saying pull down each individual data line?

These are Neopixels, right? And they’re all daisy chained together in one long string? If so, you only have one single data line that you need to pull down, at the end of the string.

You are correct, as I mentioned a bit earlier someone suggested I connect a 20k resistor between ground and the end of the string. I’ve tried with a 20k and a 500 ohm and the problem persists.

and I found the problem. It was the code.

for(int i = NUM_LEDS;i>0;i–){}

should be

for(int i = NUM_LEDS-1;i>0;i–){}

semantics eh.

In addition you want i>=0 - otherwise leds[0] will never get set :slight_smile:

In this case leds[i] = leds[i-1] was inside of the loop so I didnt want 0 set.