Go Down

Topic: fill_rainbow function questions.... ? (Read 283 times) previous topic - next topic


What I want to do is set up an array that would have 6 black (off) LED's, and then 6 blue LED's. The blue LED's would have varying levels of brightness. So the LED array would have 6 black LEDs, then 6 blue, 12 total. I then want to "move' this array similar to how the program below does it within the loop.

I saw this example of fill_rainbow. Its from the FastLED library:

When I look at the code, I see that it takes an existing array, then "moves" it along the LED strip.

With this line
Code: [Select]
fill_rainbow( leds + 1, NUM_LEDS - 1, --starthue, 20), does the number 20 refer to the number of LEDs it will squish the array into?

I am still a bit confused as to how this program "moves" the array.

If I stretch out the array (ie: change the value from 20, to ?), does the function do math and add more detail to the array? I say this because if I change the value to 100, there is a lot more detail for the colours.

Anyways, I am looking for a bit more clarity on this function

Code: [Select]
#include <FastLED.h>

#define LED_PIN     6

// Information about the LED strip itself
#define NUM_LEDS    30
#define CHIPSET     WS2812

#define BRIGHTNESS  19

// FastLED v2.1 provides two color-management controls:
//   (1) color correction settings for each LED strip, and
//   (2) master control of the overall output 'color temperature'
// THIS EXAMPLE demonstrates the second, "color temperature" control.
// It shows a simple rainbow animation first with one temperature profile,
// and a few seconds later, with a different temperature profile.
// The first pixel of the strip will show the color temperature.
// HELPFUL HINTS for "seeing" the effect in this demo:
// * Don't look directly at the LED pixels.  Shine the LEDs aganst
//   a white wall, table, or piece of paper, and look at the reflected light.
// * If you watch it for a bit, and then walk away, and then come back
//   to it, you'll probably be able to "see" whether it's currently using
//   the 'redder' or the 'bluer' temperature profile, even not counting
//   the lowest 'indicator' pixel.
// FastLED provides these pre-conigured incandescent color profiles:
//     Candle, Tungsten40W, Tungsten100W, Halogen, CarbonArc,
//     HighNoonSun, DirectSunlight, OvercastSky, ClearBlueSky,
// FastLED provides these pre-configured gaseous-light color profiles:
//     WarmFluorescent, StandardFluorescent, CoolWhiteFluorescent,
//     FullSpectrumFluorescent, GrowLightFluorescent, BlackLightFluorescent,
//     MercuryVapor, SodiumVapor, MetalHalide, HighPressureSodium,
// FastLED also provides an "Uncorrected temperature" profile
//    UncorrectedTemperature;

#define TEMPERATURE_1 Candle

#define TEMPERATURE_2 Halogen

// How many seconds to show each temperature before switching
#define DISPLAYTIME 40
// How many seconds to show black between switches
#define BLACKTIME   3

void loop()
  // draw a generic, no-name rainbow
  static uint8_t starthue = 0;
  fill_rainbow( leds + 1, NUM_LEDS - 1, --starthue, 20);

  // Choose which 'color temperature' profile to enable.
  uint8_t secs = (millis() / 1000) % (DISPLAYTIME * 2);
  if( secs < DISPLAYTIME) {
    FastLED.setTemperature( TEMPERATURE_1 ); // first temperature
    leds[0] = TEMPERATURE_1; // show indicator pixel
  } else {
    FastLED.setTemperature( TEMPERATURE_2 ); // second temperature
    leds[0] = TEMPERATURE_2; // show indicator pixel

  // Black out the LEDs for a few secnds between color changes
  // to let the eyes and brains adjust
  //if( (secs % DISPLAYTIME) < BLACKTIME) {
  //  memset8( leds, 0, NUM_LEDS * sizeof(CRGB));

void setup() {
  delay( 3000 ); // power-up safety delay
  // It's important to set the color correction for your LED strip here,
  // so that colors can be more accurately rendered through the 'temperature' profiles
  FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalSMD5050 );
  FastLED.setBrightness( BRIGHTNESS );


The number 20 controls the colour difference between adjacent LEDs in the rainbow pattern. Google, don't guess!

Go Up