Skip to content

Instantly share code, notes, and snippets.

@rpearl
Last active August 29, 2015 14:23
Show Gist options
  • Save rpearl/e91a0d7ce07629fe10c0 to your computer and use it in GitHub Desktop.
Save rpearl/e91a0d7ce07629fe10c0 to your computer and use it in GitHub Desktop.
#include <FastLED.h>
#define NUM_LEDS 197
#define RANDOM 0
#define IN_ORDER 1
CRGB leds[NUM_LEDS];
// 1, 2
// 3, 7
// 8, 14
// 15
// 16, 21
// 22, 27
// 28, 32
// 33, 44
// 45, 54
// 55, 59
// 60, 67
// 68, 69
// 70, 79, +1
// 79.1, 79.5, +5 (actual indices 80, 85)
//
void setup() {
FastLED.addLeds<APA102, 11, 13, BGR>(leds, NUM_LEDS);
FastLED.setBrightness(10);
FastLED.clear();
FastLED.setCorrection(TypicalSMD5050);
//Serial.begin(56700);
randomSeed(analogRead(0));
}
void chase(const CRGBPalette256& pal, uint16_t wait, uint8_t select_mode) {
uint8_t next = 0;
uint8_t offset;
uint8_t len = sizeof(pal) / sizeof(pal[0]);
uint8_t index = 0;
for (uint8_t i = 0; i < 1000; i++) {
offset = 1;
FastLED.show();
FastLED.delay(wait);
memmove8(&leds[1], &leds[0], (NUM_LEDS-1)*sizeof(CRGB));
if (next == 0) {
offset = 2*random(2) + 1;
if (select_mode == RANDOM) {
index = random(len);
} else {
index = (index + 1) % len;
}
CRGB c = ColorFromPalette(pal, index, 255, NOBLEND);
for (uint8_t j = 0; j < offset; j++) {
leds[j] = c;
}
if (offset == 3) {
leds[0].fadeToBlackBy(128);
leds[2].fadeToBlackBy(128);
}
next = random(5, 20);
} else {
leds[0] = CRGB::Black;
next--;
}
}
}
void loop() {
//chase(LavaColors_p, 60);
//chase(RainbowColors_p, 60, IN_ORDER);
//chase(CRGB(255, 0, 0), 50);
//chase(CRGB(255, 255, 0));
//chase(CRGB( 0, 255, 0));
//chase(CRGB( 0, 255, 255));
//chase(CRGB( 0, 0, 255));
//chase(CRGB(255, 0, 255));
/*
for (uint8_t i = 0; i < 360; i+=5) {
fill_rainbow(&leds[0], NUM_LEDS, i);
FastLED.show();
delay(20);
}
*/
//chase(CRGB(0,0,255));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment