Skip to content

Instantly share code, notes, and snippets.

@jwhendy
Last active October 23, 2015 04:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jwhendy/9fbaf21d299621e969bb to your computer and use it in GitHub Desktop.
Save jwhendy/9fbaf21d299621e969bb to your computer and use it in GitHub Desktop.
A quick demo of using fill_gradient per a request on the FastLED Google+ community.
#include "FastLED.h"
// fast led constants
#define DATA_PIN 3 // change to your data pin
#define COLOR_ORDER GRB // if colors are mismatched; change this
#define NUM_LEDS 28 // change to the number of LEDs in your strip
// change WS2812B to match your type of LED, if different
// list of supported types is here:
// https://github.com/FastLED/FastLED/wiki/Overview
#define LED_TYPE WS2812B
// this creates an LED array to hold the values for each led in your strip
CRGB leds[NUM_LEDS];
// fill_gradient variables (except direction as I wasn't sure what variable type to make it?)
int start_pixel = 0;
int end_pixel = 28;
CHSV start_hue = CHSV(0, 255, 100);
CHSV end_hue = CHSV(180, 255, 100);
void setup()
{
// the wiki features a much more basic setup line:
FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS);
}
void loop()
{
/*
arguments are:
array: the name of your "CRGB name[NUM_LEDS] definition above
start_led: which index number (0 is first pixel) to start with?
start_hue: CHSV form (hue, sat, bright) of color/brightness for start led
end_led: which is the last pixel in the gradient?
end_hue: CHSF form for color of last pixel in gradient
direction: thinking of a 0-255 color wheel, which direction should the
gradient ramp through? Change the below to SHORTEST_HUES and you'll
see that it goes red to blue through violet. Compare that to this, which
goes the "long way" through yellow, green, and cyan.
directions explained here: http://fastled.io/docs/3.1/colorutils_8h_source.html
*/
fill_gradient(leds,
start_pixel,
start_hue,
end_pixel,
end_hue,
LONGEST_HUES);
FastLED.show();
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment