Question status: ANSWERED. Thank you for the help! The question:

(Matt Wagner) #1

Question status: ANSWERED. Thank you for the help!

The question:
I am running an Arduino Uno, including the FastLED library (v3.1.6), and running a 300 pixel Neopixel led tape. Linked is the example sketch (the example works!) but I need to make a change and can’t figure out how. Instead of displaying blue as used in the demo, I need the first 100 pixels as green, the next 100 as yellow, and the last 100 as red.

Every attempt I have made to support this change has caused bizarre results.

What would be the best way to achieve this goal?

(Patrick Aversenq) #2

for(int led = 0; led < 100; led++) {
leds[led] = CRGB::Green;
for(int led = 100; led < 200; led++) {
leds[led] = CRGB::Yellow;
for(int led = 200; led <NUM_LEDS ; led++) {
leds[led] = CRGB::Red;
for(int led =numLedsToLight; led <NUM_LEDS ; led++) {
leds[led] = CRGB::Black;

(Marc Miller) #3

Try this and see if it’s what you’re looking for:

Since you want three sections of color,
on line 12, update this part:
map(val, 0, 1023, 0, NUM_LEDS);
map(val, 0, 1023, 0, NUM_LEDS/3);

And then replace line 17 with:
leds[led] = CRGB::Green;
leds[led + (NUM_LEDS/3)] = CRGB::Yellow;
leds[led + (NUM_LEDS/3*2)] = CRGB::Red;

(Yves BAZIN) #4

Your code is illuminating the number of leds depending on the value is reading on pin2.
Then what do you wanna do 1/3. Red 1/3 blue 1/3green ?

(Matt Wagner) #5

Thank you for all the support! Patricl Aversemq, that worked perfectly.