Hi All,  Quick question regarding "fill_gradient" I'm hoping to light up a strip one

Hi All,

Quick question regarding “fill_gradient”

I’m hoping to light up a strip one LED at a time starting from 0 to 59, using the colors generated by fill-gradient. The whole strip lights up at once, instead of one led at a time and I’m not sure what I’m doing wrong. Any help would be appreciated!

I’m using an Uno, Ver1.6.5 , FastLED3.1, mac, neopixel 60 strip.

#include “FastLED.h”
#define NUM_LEDS 60
#define DATA_PIN 6
#define BRIGHTNESS 255
CRGB leds[NUM_LEDS];
CHSV gradStartColor(0,255,255); // Gradient start color.
CHSV gradEndColor(160,255,255); // Gradient end color.

void setup() {
FastLED.addLeds<NEOPIXEL,DATA_PIN>(leds, NUM_LEDS);
delay(3000); //startupdelay
}

void loop() {
for( int i = 0; i < NUM_LEDS; i++){
fill_gradient (leds, 0, gradStartColor, 59, gradEndColor, SHORTEST_HUES);
delay(100);
FastLED.show();
FastLED.clear();
}

}

@Neil_P : change your loop to:

void loop() {
for( int i = 0; i < NUM_LEDS; i++){
fill_gradient (leds, 0, gradStartColor, i, gradEndColor, SHORTEST_HUES);
delay(100);
FastLED.show();
FastLED.clear();
}
}

When you put 59 in the fill_gradient, you are filling the whole strip. Change it to i and this way will fill one led at a time.

Ken, thanks for the feedback, this is a great step and turns the pixels on one by one, and moves the gradient as “i” increases, but I would like the gradient to stay in place and just the leds to light one by one.

e.g. led 0 is always hue 0, led 30 is approx hue 80, led 59 is always hue 160.

maybe i’m taking the wrong approach and need to map the values of the pixel number against the hue values?

Neil, here’s an idea: in addition to creating CRGB leds[NUM_LEDS] at the top of the program make a second one for holding temporary values, such as CRGB ledsTemp[NUM_LEDS]. Fill the gradient into this temp array, and then you can copy one pixel at a time to the normal leds array and display.
leds[i] = ledsTemp[i];

Marc, it works!! Thank you so much for this advice!! This is fantastic.

I was working on mapping the values of i and hue against each other, but because I was wanting to go around the colour wheel in a negative direction it was proving problematic.

Here’s the code for others wanting to do something similar

#include “FastLED.h”
#define NUM_LEDS 60
#define DATA_PIN 6
#define BRIGHTNESS 255
CRGB leds[NUM_LEDS];
CRGB ledsTemp[NUM_LEDS]; //for holding temporary values
CHSV gradStartColor(0,255,255); // Gradient start color.
CHSV gradEndColor(160,255,255); // Gradient end color.

void setup() {
FastLED.addLeds<NEOPIXEL,DATA_PIN>(leds, NUM_LEDS);
delay(3000); //startupdelay
fill_gradient (ledsTemp, 0, gradStartColor, 59, gradEndColor, SHORTEST_HUES); ////Fill the gradient into this temp array

}

void loop() {
for( int i = 0; i < NUM_LEDS; i++){
leds[i] = ledsTemp[i]; //copy one pixel at a time to the normal leds array and display
delay(50);
FastLED.show();
//FastLED.clear();
}

}