1

I’m using an Arduino Uno and a fastLed WS2812B. I have the leds set up correctly. Every 2 seconds, the lights pause of about a second and display seemingly random colors.

Does anyone know what's wrong?

My code:

#include <FastLED.h>

#define LED_PIN   7
#define NUM_LEDS  10

CRGB leds[NUM_LEDS];


void setup() {
  FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);

}

void loop() {
  for (int i = 0; i < NUM_LEDS; i++){
    leds[i] = CRGB(0,0,255);
    FastLED.show();
    delay(100);
  }
  for (int i = 0; i < NUM_LEDS; i++){
    leds[i] = CRGB(255,0,0);
    FastLED.show();
    delay(100);
  }
}
10
  • Is this on an Arduino or something else like ESP8266? Commented Jan 12, 2019 at 21:36
  • It is an Arduino Uno Commented Jan 12, 2019 at 21:39
  • How are you powering the LEDs?
    – Majenko
    Commented Jan 12, 2019 at 22:50
  • I noted that each example in fastled library, ‘’clear’’ the array, after running ‘’show’’ function. Try with: leds[i]= CRGB::Black; after ‘’show’’.
    – leoc7
    Commented Jan 12, 2019 at 22:57
  • what happens if you put FastLED.show(); and delay(100); after the for loop
    – jsotola
    Commented Jan 12, 2019 at 23:08

1 Answer 1

-1

I have run the code on the Arduino simulator online. If it is working in the Arduino Simulator chances are less that it has to do something with the code itself.

Hence, also as the root cause was found to be about sharing the ground @Majenko

This is also one example of solving the problem step by step. validating one section after the other. using the simulator you can verify that the code is working fine. later, proceed to verify the hardware. I hope this helps.

You can verify the FastLED code here (you can modify the parameters)

enter image description here

2
  • Is this really answering the question? It seems to be saying what the problem isn't.
    – Nick Gammon
    Commented Sep 2, 2020 at 11:44
  • @NickGammon I too agree ☑️. I tried to show how I could deduce the root cause to be hardware and not the library or the code itself. The OP has also found the root cause to be hardware.
    – ArduinoFan
    Commented Sep 2, 2020 at 12:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.