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);
}
}
1 Answer 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)
-
Is this really answering the question? It seems to be saying what the problem isn't.2020年09月02日 11:44:35 +00:00Commented 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– ArduinoFan2020年09月02日 12:00:13 +00:00Commented Sep 2, 2020 at 12:00
FastLED.show();
anddelay(100);
after thefor
loop