Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
/* rainbow_center
By: Andrew Tuline
Date: Jan, 2018
Rainbow marching from the center to the ends of the strand using the fill_rainbow routine.
Note: You may need to adjust the 'huemod' variable to match your length of strand if you want to mirror the effect.
#include "FastLED.h" // FastLED library.
#if FASTLED_VERSION < 3001000
#error "Requires FastLED 3.1 or later; check github for latest code."
// Fixed definitions cannot change on the fly.
#define LED_DT 12 // Serial data pin
#define LED_CK 11 // Clock pin for WS2801 or APA102
#define COLOR_ORDER BGR // It's GRB for WS2812B and GBR for APA102
#define LED_TYPE APA102 // What kind of strip are you using (APA102, WS2801 or WS2812B)?
#define NUM_LEDS 40 // Number of LED's
// Initialize changeable global variables.
uint8_t max_bright = 255; // Overall brightness definition. It can be changed on the fly.
struct CRGB leds[NUM_LEDS]; // Initialize our LED array.
void setup() {
// LEDS.addLeds<LED_TYPE, LED_DT, COLOR_ORDER>(leds, NUM_LEDS); // For WS2812B
LEDS.addLeds<LED_TYPE, LED_DT, LED_CK, COLOR_ORDER>(leds, NUM_LEDS); // For APA102 or WS2801
set_max_power_in_volts_and_milliamps(5, 1000); // FastLED 2.1 Power management set at 5V, 500mA
} // setup()
void loop () {
rainbow_center(200, 10);;
} // loop()
void rainbow_center(uint8_t thisdelay, uint8_t deltahue) { // The fill_rainbow call doesn't support brightness levels.
uint8_t thishue = millis()*(255-thisdelay)/255; // To change the rate, add a beat or something to the result. 'thisdelay' must be a fixed value.
uint8_t huemod = 175;
fill_rainbow(leds, NUM_LEDS/2, thishue, deltahue); // Use FastLED's fill_rainbow routine from the start to the center
fill_rainbow(leds+NUM_LEDS/2, NUM_LEDS/2, thishue+huemod, deltahue*-1); // And from the center to the far end
} // rainbow_center()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.