Hello, I'm currently doing LED caps project but my WS2812 led strip not light up after uploading the code.Can someone help me? Thanks!
2led_strip.ino (1.32 KB)
Hello, I'm currently doing LED caps project but my WS2812 led strip not light up after uploading the code.Can someone help me? Thanks!
2led_strip.ino (1.32 KB)
Hi,
Welcome to the forum.
Please read the post at the start of any forum , entitled "How to use this Forum".
OR
http://forum.arduino.cc/index.php/topic,148850.0.html.
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
What model Arduino are you using?
Thanks.. Tom... ![]()
These lines:
#define DATA_PIN 5 // Data pin for the first LED strip
#define DATA_PIN 6 // Data pin for the second LED strip
define DATA_PIN to 5 and then redefine it to 6. If you have compiler warnings enabled at File > Preferences > Compiler warnings, you would get a helpful warning about this:
C:\Users\per\AppData\Local\Temp\arduino_modified_sketch_878093\sketch_jan14a.ino:7:0: warning: "DATA_PIN" redefined
#define DATA_PIN 6 // Data pin for the second LED strip
C:\Users\per\AppData\Local\Temp\arduino_modified_sketch_878093\sketch_jan14a.ino:6:0: note: this is the location of the previous definition
#define DATA_PIN 5 // Data pin for the first LED strip
So these lines:
LEDS.addLeds<WS2812, DATA_PIN, RGB>(leds[0], NUM_LEDS_PER_STRIP);
LEDS.addLeds<WS2812, DATA_PIN, RGB>(leds[1], NUM_LEDS_PER_STRIP);
are the equivalent of:
LEDS.addLeds<WS2812, 6, RGB>(leds[0], NUM_LEDS_PER_STRIP);
LEDS.addLeds<WS2812, 6, RGB>(leds[1], NUM_LEDS_PER_STRIP);
I'm guessing you expected it to be like this:
LEDS.addLeds<WS2812, 5, RGB>(leds[0], NUM_LEDS_PER_STRIP);
LEDS.addLeds<WS2812, 6, RGB>(leds[1], NUM_LEDS_PER_STRIP);
but C++ doesn't work like that. You need to use a different name for each macro:
#define DATA_PIN1 5 // Data pin for the first LED strip
#define DATA_PIN2 6 // Data pin for the second LED strip
LEDS.addLeds<WS2812, DATA_PIN1, RGB>(leds[0], NUM_LEDS_PER_STRIP);
LEDS.addLeds<WS2812, DATA_PIN2, RGB>(leds[1], NUM_LEDS_PER_STRIP);
Or better yet, use an array and a for loop.