Skip to content

Instantly share code, notes, and snippets.

@scottyallen
Created April 29, 2016 04:42
Show Gist options
  • Save scottyallen/ecaee28f537cf94e3aa30bb8347e0654 to your computer and use it in GitHub Desktop.
Save scottyallen/ecaee28f537cf94e3aa30bb8347e0654 to your computer and use it in GitHub Desktop.
#include "FastLED.h"
FASTLED_USING_NAMESPACE
#if FASTLED_VERSION < 3001000
#error "Requires FastLED 3.1 or later; check github for latest code."
#endif
#define BRIGHTNESS 96
#define FRAMES_PER_SECOND 240
int count_leds(const int* num_leds_arr, const int len) {
int count = 0;
for (int i = 0; i < len; i++) {
count += num_leds_arr[i];
}
return count;
}
const int NUM_LEDS_PER_STRIP[8] = {277, 277, 24, 39, 14, 9, 105, 65};
const int NUM_LEDS = count_leds(NUM_LEDS_PER_STRIP, 8);
static CRGB strip1[277];
static CRGB strip2[277];
static CRGB strip3[24];
static CRGB strip4[39];
static CRGB strip5[14];
static CRGB strip6[9];
static CRGB strip7[105];
static CRGB strip8[65];
// For mirroring strips, all the "special" stuff happens just in setup. We
// just addLeds multiple times, once for each strip
void setup() {
FastLED.addLeds<WS2812B, 2, GRB>(strip1, 0, NUM_LEDS_PER_STRIP[0]);
FastLED.addLeds<WS2812B, 3, GRB>(strip2, 0, NUM_LEDS_PER_STRIP[1]);
FastLED.addLeds<WS2812B, 4, GRB>(strip3, 0, NUM_LEDS_PER_STRIP[2]);
FastLED.addLeds<WS2812B, 5, GRB>(strip4, 0, NUM_LEDS_PER_STRIP[3]);
FastLED.addLeds<WS2812B, 6, GRB>(strip5, 0, NUM_LEDS_PER_STRIP[4]);
FastLED.addLeds<WS2812B, 7, GRB>(strip6, 0, NUM_LEDS_PER_STRIP[5]);
FastLED.addLeds<WS2812B, 8, GRB>(strip7, 0, NUM_LEDS_PER_STRIP[6]);
FastLED.addLeds<WS2812B, 9, GRB>(strip8, 0, NUM_LEDS_PER_STRIP[7]);
// set master brightness control
FastLED.setBrightness(BRIGHTNESS);
}
struct LedSegment {
CRGB *strip;
int start_offset;
int num_leds;
};
LedSegment SEGMENTS[22] = {
{strip2, 0, 40},
{strip2, 40, 65},
{strip1, 0, 41},
{strip8, 0, 40},
{strip2, 105, 66},
{strip4, 0, 24},
{strip4, 24, 5},
{strip4, 29, 10},
{strip1, 41, 26},
{strip3, 0, 10},
{strip6, 0, 9},
{strip8, 40, 10},
{strip5, 0, 4},
{strip5, 4, 10},
{strip3, 10, 14},
{strip8, 50, 15},
{strip7, 0, 25},
{strip7, 25, 15},
{strip7, 40, 65},
{strip1, 67, 105},
{strip2, 171, 106},
{strip1, 172, 105}
};
const int NUM_SEGMENTS = 22;
void clear() {
for (int i = 0; i < NUM_SEGMENTS; i ++) {
LedSegment segment = SEGMENTS[i];
for (int j = segment.start_offset; j < (segment.start_offset + segment.num_leds); j++) {
segment.strip[j] = CRGB::Black;
}
}
}
void fill_segment(int segment_num, CRGB color) {
LedSegment segment = SEGMENTS[segment_num - 1];
for (int i = segment.start_offset; i < (segment.start_offset + segment.num_leds); i++) {
segment.strip[i] = color;
}
}
void loop() {
clear();
fill_segment(17, CRGB::White);
fill_segment(18, CRGB::White);
fill_segment(19, CRGB::White);
fill_segment(21, CRGB::White);
fill_segment(22, CRGB::White);
fill_segment(20, CRGB::White);
FastLED.show();
delay(200);
clear();
fill_segment(2, CRGB::White);
fill_segment(5, CRGB::White);
fill_segment(19, CRGB::White);
fill_segment(16, CRGB::White);
fill_segment(12, CRGB::White);
fill_segment(4, CRGB::White);
FastLED.show();
delay(200);
clear();
fill_segment(1, CRGB::White);
fill_segment(4, CRGB::White);
fill_segment(8, CRGB::White);
fill_segment(7, CRGB::White);
fill_segment(6, CRGB::White);
fill_segment(3, CRGB::White);
FastLED.show();
delay(200);
clear();
fill_segment(6, CRGB::White);
fill_segment(10, CRGB::White);
fill_segment(15, CRGB::White);
fill_segment(17, CRGB::White);
fill_segment(9, CRGB::White);
FastLED.show();
delay(200);
clear();
fill_segment(13, CRGB::White);
fill_segment(14, CRGB::White);
fill_segment(16, CRGB::White);
fill_segment(18, CRGB::White);
fill_segment(15, CRGB::White);
FastLED.show();
delay(200);
clear();
fill_segment(8, CRGB::White);
fill_segment(12, CRGB::White);
fill_segment(14, CRGB::White);
fill_segment(11, CRGB::White);
FastLED.show();
delay(200);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment