Erratic LED behavior

Hello,

Hopefully this is a simple question for someone to answer and more hopefully, simple enough for me to understand the answer.

Each time I run this program, different LED’s will behave unexpectedly. I’m using a strip of 60 WS21812B LED’s controlling it with an Elegoo UNO R3.

Here is my code:

// FastLED - Version: Latest 
#include <FastLED.h>
#define LED_Pin 2
#define NUM_LEDS 60
CRGB leds[NUM_LEDS];


unsigned min = 0;


void setup() {
  FastLED.addLeds<WS2812, LED_Pin,GRB>(leds, NUM_LEDS);
  FastLED.setBrightness(40);
  FastLED.clear();
  FastLED.show();
//  Initialize all LEDs 
  for (int x=0;x<10;x++){
leds[x] = CRGB::Green;
leds[x+10] = CRGB::Red;
leds[x+20] = CRGB::Blue;
FastLED.show();
}
delay(1000);
}
void loop() {
leds[min] = CRGB::Black;
FastLED.show();
min++;
delay(1000);
 }

What is supposed to happen is 30 of the LED’s should turn on; 10 green, 10 red, and 10 blue. They are then supposed to turn off one at a time.

All the LED’s initialize correctly. When it comes to turning them off, LED’s [0-1] will behave correctly, but LED[2] will cause LED[20] to turn off. The next time I run it, LED[0] will turn off ALONG with LED[18 and 19]. Or LED[5] will turn off ALONG with LED[25-20] and they will not turn back on until LED[7] turns off.

Thank you for your assistance.

Michael

You need to use AutoFormat (control T) on your code.

Apparently "min" just keeps incrementing with no limit. That is going to cause serious problems! :astonished:

Thank you, Paul.

I can appreciate that comment, but shouldn't the code work up to the point that min exceeds the 60 LEDS on the strip our at minimum to the 30 LEDS that are lit up?

Things screw up when min is a small number like three or four or five.

Michael

I thought I did Control T. Guess it didn't work.

I suspect you have a power supply problem, post your schematic, not a frizzy drawing showing all power and ground connections. Include links to the components.

Thank you, gilshultz,

I don't think I would have ever thought of the power supply since I wasn't running what I thought was too many LED's. I was running them directly from the UNO.

I have since hooked them up to a 5V 50A power supply.

Unfortunately, I now know I have a bunch of bad LED's. I've replaced those and so far all is look great.

At least I know it was not my programming inexperience!

Thank you again for your help.

Michael

mlfriedberg:
I don't think I would have ever thought of the power supply since I wasn't running what I thought was too many LED's. I was running them directly from the UNO.

I would be concerned if you had confused an Arduino with a power supply. :astonished:

60 LEDs at maximum brightness would draw 3.3 Amps. A UNO powered via "Vin" or the equivalent "barrel jack" can plausibly supply from the "5V" pin something of the order of 100 mA, sufficient to power about two NeoPixels, or if fed from the USB jack, perhaps sufficient for nine NeoPixels. :sunglasses:

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