-
-
Save anonymous/6538b3b02798d6e5d1adec84508ab502 to your computer and use it in GitHub Desktop.
Holiday House Lights / FastLED
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <FastLED.h> | |
#define LED_PIN 7 //6 for testing, 7 for production | |
#define COLOR_ORDER GRB | |
#define CHIPSET WS2811 | |
#define NUM_LEDS 300 //88 for testing, 300 for prodction | |
#define BRIGHTNESS 200 | |
#define FRAMES_PER_SECOND 30 | |
bool gReverseDirection = false; | |
unsigned long previousMillis = 0; | |
unsigned long currentMillis; | |
int mode; | |
long totalModes = 3; | |
CRGB leds[NUM_LEDS]; | |
CRGBPalette16 gPal; | |
void setup() { | |
delay(3000); // sanity delay | |
FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip ); | |
FastLED.setBrightness( BRIGHTNESS ); | |
randomSeed(analogRead(0)); | |
mode = random(totalModes); | |
} | |
extern const TProgmemRGBGradientPalettePtr gGradientPalettes[]; | |
void loop() | |
{ | |
currentMillis = millis(); | |
switch (mode) { | |
case 0: | |
runRainbow(); | |
twinkle(); | |
break; | |
case 1: | |
palettetest(leds, NUM_LEDS, gGradientPalettes[0]); | |
twinkle(); | |
break; | |
case 2: | |
palettetest(leds, NUM_LEDS, gGradientPalettes[1]); | |
twinkle(); | |
break; | |
} | |
} | |
void runColor(CRGB color) { | |
if (currentMillis - previousMillis >= 200) { | |
previousMillis = currentMillis; | |
fill_solid(leds, NUM_LEDS, color); // | |
FastLED.show(); | |
} | |
} | |
void runRainbow() { | |
if (currentMillis - previousMillis >= 30) { | |
previousMillis = currentMillis; | |
static uint8_t hue = 0; | |
fill_rainbow(leds, NUM_LEDS, hue++); | |
FastLED.show(); | |
} | |
} | |
void twinkle(){ | |
//create random twinkle | |
int twinkle = random(NUM_LEDS); | |
int prob = random(1,25); | |
if (prob==2){ | |
leds[twinkle] = CRGB::White; | |
} | |
FastLED.show(); | |
//FastLED.delay(25); | |
} | |
void palettetest( CRGB* ledarray, uint16_t numleds, const CRGBPalette16& gCurrentPalette) | |
{ | |
if (currentMillis - previousMillis >= 30) { | |
previousMillis = currentMillis; | |
static uint8_t startindex = 0; | |
startindex--; | |
fill_palette( ledarray, numleds, startindex, (256 / NUM_LEDS) + 1, gCurrentPalette, 255, LINEARBLEND); | |
FastLED.show(); | |
} | |
} | |
DEFINE_GRADIENT_PALETTE( holly_gp){ | |
0, 0, 255, 0, //green | |
48, 0, 255, 0, //green | |
49, 255, 0, 0, //red | |
64, 255, 0, 0, //red | |
65, 0, 255, 0, //green | |
114, 0, 255, 0, //green | |
115, 255, 0, 0, //red | |
118, 255, 0, 0, //red | |
119, 0, 255, 0, //green | |
168, 0, 255, 0, //green | |
169, 255, 0, 0, //red | |
184, 255, 0, 0, //red | |
185, 0, 255, 0, //green | |
234, 0, 255, 0, //green | |
235, 255, 0, 0, //red | |
255, 255, 0, 0 //red | |
}; | |
DEFINE_GRADIENT_PALETTE( candycane_gp){ | |
0 , 128, 128, 128, //white | |
32 , 128, 128, 128, //white | |
33 , 255, 0, 0, //red | |
66 , 255, 0, 0, //red | |
67 , 128, 128, 128, //white | |
100 , 128, 128, 128, //white | |
101 , 255, 0, 0, //red | |
134 , 255, 0, 0, //red | |
135 , 128, 128, 128, //white | |
168 , 128, 128, 128, //white | |
169 , 255, 0, 0, //red | |
202 , 255, 0, 0, //red | |
203 , 128, 128, 128, //white | |
236 , 128, 128, 128, //white | |
237 , 255, 0, 0, //red | |
255 , 255, 0, 0 //red | |
}; | |
DEFINE_GRADIENT_PALETTE( snowynight_gp){ | |
0, 163,182,199, | |
41, 188,192,200, | |
117, 117, 157, 240, | |
204, 117, 224, 240, | |
255, 163,182,199 | |
}; | |
DEFINE_GRADIENT_PALETTE( silvergold_gp){ | |
46, 191, 201, 224, | |
127, 255, 236, 133, | |
204, 191, 201, 224 | |
}; | |
const TProgmemRGBGradientPalettePtr gGradientPalettes[] = { | |
holly_gp, | |
candycane_gp, | |
snowynight_gp, | |
silvergold_gp | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment