Skip to content

Instantly share code, notes, and snippets.

@danasf
Last active August 29, 2015 13:58
Show Gist options
  • Select an option

  • Save danasf/9986219 to your computer and use it in GitHub Desktop.

Select an option

Save danasf/9986219 to your computer and use it in GitHub Desktop.
Rainbow LEDs for multiple strips
#include "FastLED.h"
// number of strips
#define NUM_STRIPS 3
// number of lights per strip, if equal
#define NUM_LEDS 2
struct CRGB leds1[NUM_LEDS];
struct CRGB leds2[NUM_LEDS];
struct CRGB leds3[NUM_LEDS];
/*
Create an array of starting hue values 0-255,
in this case we're starting with red,green,blue
you can use a color wheel, (degrees/360)*255
http://www.ncl.ucar.edu/Applications/Images/color_18_3_lg.png
*/
uint8_t hues[NUM_STRIPS] = {0,90,160};
void setup() {
// sanity check delay - allows reprogramming if accidently blowing power w/leds
delay(2000);
// init strips on pins 7,8,9
FastLED.addLeds<WS2812, 9, GRB>(leds1, NUM_LEDS);
FastLED.addLeds<WS2812, 8, GRB>(leds2, NUM_LEDS);
FastLED.addLeds<WS2812, 7, GRB>(leds3, NUM_LEDS);
}
void loop() {
// fill with rainbows!!
fill_rainbow(leds1, NUM_LEDS, hues[0]);
fill_rainbow(leds2, NUM_LEDS, hues[1]);
fill_rainbow(leds3, NUM_LEDS, hues[2]);
FastLED.show();
// loop through # of strips
for(uint8_t i = 0; i < NUM_STRIPS; i++) {
// if hue > 255 set to 0, else add 1.
hues[i] == 255 ? hues[i]=0 : hues[i]++;
}
// delay
delay(100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment