Hi All, I am just starting with Arduino and FastLEd and I am trying

fastled-support
gplus
(Ian Martin) #1

Hi All,

I am just starting with Arduino and FastLEd and I am trying to work out how to use a defined GRADIENT_PALETTE.

So my 1st test sketch has failed. It is meant to fill the strip with a color and over time slowly move the color up the gradient (simple but it is the start of hopefully a more complex sequence)

My problem is that the ColorHue variable keeps getting reset back to zero. The code works fine with ColorHue incrementing by 1until I put it in this line

leds[i] = ColorFromPalette( myPal, ColorHue,LEDBrightness,LINEARBLEND );

Then the Serial.print(ColorHue); returns 0 every single pass of the loop.

Full Code Below (PS I will not beusing delay it was inserted to test :slight_smile: )

Any help would be great

Many Thanks Ian

___________________________________________________________
/* 1st Test sketch*/

	#include <FastLED.h>  // Include the FastLed Library
	
	// Define Constants
	#define LED_PIN     6
	#define COLOR_ORDER GRB
	#define CHIPSET     WS2812B
	#define NUM_LEDS    8
	
// Define Variables
uint8_t ColorHue = 0;
uint8_t ChangeInHue = 15;
uint8_t LEDBrightness = 255;
int HueDelay = 500;

DEFINE_GRADIENT_PALETTE ( heatmap_gp ) {
0, 255, 255,0, //Yellow
32, 255, 128, 0, //Orange
64, 255,0, 0, //Red
96, 255,0,255, //Pink
128, 128,0,255, //Purple
160, 255,0, 255, //Pink
192, 255,0, 0, //Red
224, 255, 128, 0, //Orange
255, 255, 255,0}; //Yellow Palette End

CRGB leds[NUM_LEDS]; // Define a strip of NUM_LEDS named “leds”
CRGBPalette16 myPal = heatmap_gp; //define myPal as a palette using gradient palette heatmap_gp

void setup() {
delay(2000); // Soft start

Serial.begin(9600);      // open the serial port at 9600 bps

FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS);  // Define the LED array "leds" parameters

pinMode(LED_PIN, OUTPUT); //Set the LED Pin as an Output

set_max_power_in_volts_and_milliamps(5, 500);  // FastLED Power management set at 5V, 500mA

} // setup end

void loop() {

for (int i = 0; i <= NUM_LEDS; i++) {
	leds[i] = ColorFromPalette( myPal, ColorHue,LEDBrightness,LINEARBLEND );
} // End For i loop

FastLED.show(); //Show the lights
delay(HueDelay);
ColorHue++;

Serial.print(ColorHue); // print
Serial.print("\t"); // prints a tab

//EVERY_N_MILLISECONDS(HueDelay){
	//ColorHue++; // Change the color by 1 
//} //Every_n_milliseconds end

} // Loop End

(Ian Martin) #2

This works but I need the for i loop to work to give me the functionality I want - I will keep poking it to see what happens :wink:

void loop() {

CRGB color = ColorFromPalette(myPal, ColorHue);
fill_solid(leds, NUM_LEDS, color);

/*
for (int i = 0; i <= NUM_LEDS; i++) {
	leds[i] = ColorFromPalette( myPal, ColorHue,LEDBrightness,LINEARBLEND );
	//leds[i] = ColorFromPalette( myPal, ColorHue,LEDBrightness,NOBLEND );
	} // End For i loop
*/

FastLED.show(); //Show the lights

Serial.print(ColorHue); // print
Serial.print("\t"); // prints a tab

EVERY_N_MILLISECONDS(HueDelay){
	ColorHue++; // Change the color by 1 
} //Every_n_milliseconds end

} // Loop End