Last active
September 4, 2018 22:01
-
-
Save carnal0wnage/e0367a29413162ce5e533263de069421 to your computer and use it in GitHub Desktop.
stranger_things.ino
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 NUM_LEDS 100 | |
#define COLOR_ORDER RGB | |
CRGB leds[NUM_LEDS]; | |
//I have a few additional integers in here from different tests. | |
int y = 1; | |
int z = 0; | |
int w = 5; | |
int i = 20; | |
int a = 0; | |
int t = 0; | |
//https://www.woodlandmanufacturing.com/articles/news/how-to-make-a-stranger-things-alphabet-sign-with-lights-code/ | |
// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX | |
//7 + 9 + 16 = 32 | |
//7 + 9 + 16 = 32 --> 64 | |
//8 + 8 + 14 + 6 = 36 --> 100 | |
//String letterIndex = "-------A--B--C--D--E--F--G--H--I-------R--Q--P--O--N--M--L--K--J--------S--T--U--V--W--X--Y--Z------"; | |
String letterIndex = "------N--O-P--Q--R--S-T--U--V---W--X--Y--Z--------M--L--K--J--I--H--G--F--E--D--C--B--A-------------"; | |
String colorLetterIndex = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | |
uint32_t colorIndex[26] = { | |
0xFFF0C4, // A | |
0x0000FF, // B | |
0xFF00FF, // C | |
0x00FFB9, // D | |
0x0000FF, // E | |
0xFCEE21, // F | |
0xFF0000, // G | |
0x00FFB9, // H | |
0x00FFB9, // I | |
0xFF00FF, // J | |
0x0000FF, // K | |
0x00FFB9, // L | |
0xFCEE21, // M | |
0xFF0000, // N | |
0xFF00FF, // O | |
0x00FFB9, // P | |
0xFF00FF, // Q | |
0x00FFB9, // R | |
0xFFF0C4, // S | |
0xFCEE21, // T | |
0x0000FF, // U | |
0xFF0000, // V | |
0x00FFB9, // W | |
0xFCEE21, // X | |
0xFF00FF, // Y | |
0xFF0000, // Z | |
}; | |
static byte initialHue = 0; | |
byte changeInHue = 255 / NUM_LEDS; | |
void setup() { FastLED.addLeds<WS2811, 6, COLOR_ORDER>(leds, NUM_LEDS); | |
Serial.begin(9600); | |
randomSeed(analogRead(0)); | |
} | |
void loop() { | |
switch(z){ | |
case 0: | |
Serial.println(z); //print to serial monitor so we can see what's going on | |
FastLED.clear(); | |
writeWord("RUN",3000,300); | |
//writeWord("ABCDEFGHIJKLMNOPQRSTUVWXYZ",3000,300); | |
Strobe(0xff, 0x00, 0x00, 20, 50, 1000); //red | |
FastLED.clear(); | |
break; | |
case 1: | |
Serial.println(z); | |
FastLED.clear(); | |
writeWord("IMHERE",3000,300); | |
Strobe(0xFF,0x80,0x00, 10, 50, 1000); //orange | |
FastLED.clear(); | |
break; | |
case 2: | |
Serial.println(z); | |
FastLED.clear(); | |
writeWord("HELP",3000,300); | |
fill_rainbow( leds, NUM_LEDS, initialHue, changeInHue); | |
FastLED.show(); | |
delay(1000); | |
FastLED.clear(); | |
break; | |
case 3: | |
Serial.println(z); | |
FastLED.clear(); | |
LOWREDUP(); | |
LOWREDDOWN(); | |
LOWREDUP(); | |
LOWREDDOWN(); | |
FastLED.clear(); | |
break; | |
case 4: | |
Serial.println(z); | |
FastLED.clear(); | |
writeWord("ELEVEN",3000,300); | |
Strobe(0xC0, 0x00, 0xFF, 10, 50, 1000); //purple | |
FastLED.clear(); | |
break; | |
case 5: | |
Serial.println(z); | |
FastLED.clear(); | |
glowup(); | |
glowdown(); | |
glowup(); | |
glowdown(); | |
FastLED.clear(); | |
break; | |
case 6: | |
Serial.println(z); | |
FastLED.clear(); | |
ONEATATIME(); | |
FastLED.clear(); | |
break; | |
case 7: | |
Serial.println(z); | |
FastLED.clear(); | |
writeWord("HAPPYHALLOWEEN",3000,300); | |
Strobe(0xff, 0x00, 0x00, 20, 50, 1000); //red | |
FastLED.clear(); | |
break; | |
case 8: | |
Serial.println(z); | |
FastLED.clear(); | |
writeWord("RIGHTHERE",3000,300); | |
Strobe(0xFF,0x80,0x00, 10, 50, 1000); //orange | |
FastLED.clear(); | |
break; | |
case 9: | |
Serial.println(z); | |
FastLED.clear(); | |
writeWord("WILL",3000,300); | |
Strobe(0xC0, 0x00, 0xFF, 10, 50, 1000); //purple | |
FastLED.clear(); | |
break; | |
case 10: | |
Serial.println(z); | |
FastLED.clear(); | |
CHRISTMAS(); | |
FastLED.clear(); | |
break; | |
default: | |
Serial.println(z); | |
FastLED.clear(); | |
CHRISTMAS(); | |
FastLED.clear(); | |
break; | |
} | |
//randomly pick a number for the case | |
z = random (0, 11); | |
} | |
void CHRISTMAS() { | |
FastLED.clear(); | |
leds[0] = CRGB (0,255,255); //aqua | |
leds[10] = CRGB (0,255,255); //aqua | |
leds[20] = CRGB (0,255,255); //aqua | |
leds[30] = CRGB (0,255,255); //aqua | |
leds[40] = CRGB (0,255,255); //aqua | |
leds[50] = CRGB (0,255,255); //aqua | |
leds[60] = CRGB (0,255,255); //aqua | |
leds[70] = CRGB (0,255,255); //aqua | |
leds[80] = CRGB (0,255,255); //aqua | |
leds[90] = CRGB (0,255,255); //aqua | |
leds[1] = CRGB (153, 50, 204); //dark orchid | |
leds[11] = CRGB (153, 50, 204); //dark orchid | |
leds[21] = CRGB (153, 50, 204); //dark orchid | |
leds[31] = CRGB (153, 50, 204); //dark orchid | |
leds[41] = CRGB (153, 50, 204); //dark orchid | |
leds[51] = CRGB (153, 50, 204); //dark orchid | |
leds[61] = CRGB (153, 50, 204); //dark orchid | |
leds[71] = CRGB (153, 50, 204); //dark orchid | |
leds[81] = CRGB (153, 50, 204); //dark orchid | |
leds[91] = CRGB (153, 50, 204); //dark orchid | |
leds[2] = CRGB (255,255,0); //yellow | |
leds[12] = CRGB (255,255,0); //yellow | |
leds[22] = CRGB (255,255,0); //yellow | |
leds[32] = CRGB (255,255,0); //yellow | |
leds[42] = CRGB (255,255,0); //yellow | |
leds[52] = CRGB (255,255,0); //yellow | |
leds[62] = CRGB (255,255,0); //yellow | |
leds[72] = CRGB (255,255,0); //yellow | |
leds[82] = CRGB (255,255,0); //yellow | |
leds[92] = CRGB (255,255,0); //yellow | |
leds[3] = CRGB (0,255,127); //spring green | |
leds[13] = CRGB (0,255,127); //spring green | |
leds[23] = CRGB (0,255,127); //spring green | |
leds[33] = CRGB (0,255,127); //spring green | |
leds[43] = CRGB (0,255,127); //spring green | |
leds[53] = CRGB (0,255,127); //spring green | |
leds[63] = CRGB (0,255,127); //spring green | |
leds[73] = CRGB (0,255,127); //spring green | |
leds[83] = CRGB (0,255,127); //spring green | |
leds[93] = CRGB (0,255,127); //spring green | |
leds[4] = CRGB (255,165,0); //orange | |
leds[14] = CRGB (255,165,0); //orange | |
leds[24] = CRGB (255,165,0); //orange | |
leds[34] = CRGB (255,165,0); //orange | |
leds[44] = CRGB (255,165,0); //orange | |
leds[54] = CRGB (255,165,0); //orange | |
leds[64] = CRGB (255,165,0); //orange | |
leds[74] = CRGB (255,165,0); //orange | |
leds[84] = CRGB (255,165,0); //orange | |
leds[94] = CRGB (255,165,0); //orange | |
leds[5] = CRGB (65,105,255); //royal blue | |
leds[15] = CRGB (65,105,255); //royal blue | |
leds[25] = CRGB (65,105,255); //royal blue | |
leds[35] = CRGB (65,105,255); //royal blue | |
leds[45] = CRGB (65,105,255); //royal blue | |
leds[55] = CRGB (65,105,255); //royal blue | |
leds[65] = CRGB (65,105,255); //royal blue | |
leds[75] = CRGB (65,105,255); //royal blue | |
leds[85] = CRGB (65,105,255); //royal blue | |
leds[95] = CRGB (65,105,255); //royal blue | |
leds[6] = CRGB (76, 0, 153); //dark purple | |
leds[16] = CRGB (76, 0, 153); //dark purple | |
leds[26] = CRGB (76, 0, 153); //dark purple | |
leds[36] = CRGB (76, 0, 153); //dark purple | |
leds[46] = CRGB (76, 0, 153); //dark purple | |
leds[56] = CRGB (76, 0, 153); //dark purple | |
leds[66] = CRGB (76, 0, 153); //dark purple | |
leds[76] = CRGB (76, 0, 153); //dark purple | |
leds[86] = CRGB (76, 0, 153); //dark purple | |
leds[96] = CRGB (76, 0, 153); //dark purple | |
leds[7] = CRGB (255,105,180); //hot pink | |
leds[17] = CRGB (255,105,180); //hot pink | |
leds[27] = CRGB (255,105,180); //hot pink | |
leds[37] = CRGB (255,105,180); //hot pink | |
leds[47] = CRGB (255,105,180); //hot pink | |
leds[57] = CRGB (255,105,180); //hot pink | |
leds[67] = CRGB (255,105,180); //hot pink | |
leds[77] = CRGB (255,105,180); //hot pink | |
leds[87] = CRGB (255,105,180); //hot pink | |
leds[97] = CRGB (255,105,180); //hot pink | |
leds[8] = CRGB (0,128,0); //dark green | |
leds[18] = CRGB (0,128,0); //dark green | |
leds[28] = CRGB (0,128,0); //dark green | |
leds[38] = CRGB (0,128,0); //dark green | |
leds[48] = CRGB (0,128,0); //dark green | |
leds[58] = CRGB (0,128,0); //dark green | |
leds[68] = CRGB (0,128,0); //dark green | |
leds[78] = CRGB (0,128,0); //dark green | |
leds[88] = CRGB (0,128,0); //dark green | |
leds[98] = CRGB (0,128,0); //dark green | |
leds[9] = CRGB (255,0,0); //red | |
leds[19] = CRGB (255,0,0); //red | |
leds[29] = CRGB (255,0,0); //red | |
leds[39] = CRGB (255,0,0); //red | |
leds[49] = CRGB (255,0,0); //red | |
leds[59] = CRGB (255,0,0); //red | |
leds[69] = CRGB (255,0,0); //red | |
leds[79] = CRGB (255,0,0); //red | |
leds[89] = CRGB (255,0,0); //red | |
leds[99] = CRGB (255,0,0); //red | |
FastLED.show(); | |
t = random(20, 30) * 1000; | |
delay(t); | |
FastLED.clear(); | |
} | |
void glowup() { | |
FastLED.clear(); | |
//Setting i determines your lowest power value. the second condition determines the max value and the y determines your step | |
for( int i = 60; i < 255; i = i + y ) { | |
int r = i; | |
int b = 0; | |
int g = 0; | |
for(int x = 0; x < NUM_LEDS; x++){ | |
leds[x] = CRGB(r,g,b); | |
} | |
FastLED.show(); | |
delay(50); | |
} | |
} | |
void glowdown() { | |
//Same thing as glowup, except in reverse | |
for (int i = 255; i > 60; i = i - y){ | |
int r = i; | |
int b = 0; | |
int g = 0; | |
for(int x = 0; x < NUM_LEDS; x++){ | |
leds[x] = CRGB(r,g,b); | |
} | |
FastLED.show(); | |
delay(50); | |
} | |
} | |
void LOWREDUP(){ | |
for( int i = 20; i < 150; i = i + y ) { | |
int r = i; | |
int b = 0; | |
int g = 0; | |
for(int x = 0; x < NUM_LEDS; x++){ | |
leds[x] = CRGB(r,g,b); | |
} | |
FastLED.show(); | |
delay(100); | |
} | |
} | |
void LOWREDDOWN(){ | |
for(int i = 150; i > 20; i = i - y) { | |
int r = i; | |
int b = 0; | |
int g = 0; | |
for(int x = 0; x < NUM_LEDS; x++){ | |
leds[x] = CRGB(r,g,b); | |
} | |
FastLED.show(); | |
delay(100); | |
} | |
} | |
void BLACKOUT(){ | |
int r = 0; | |
int b = 0; | |
int g = 0; | |
for(int x = 0; x < NUM_LEDS; x++){ | |
leds[x] = CRGB(r,g,b); | |
} | |
FastLED.show(); | |
delay(30000); | |
} | |
void ONEATATIME(){ | |
for(int j = 0; j < 3; j++) { | |
for(int i = 0 ; i < NUM_LEDS; i++ ) { | |
memset(leds, 0, NUM_LEDS * 3); | |
switch(j) { | |
case 0: leds[i].r = 255; break; | |
case 1: leds[i].g = 255; break; | |
case 2: leds[i].b = 255; break; | |
} | |
FastLED.show(); | |
delay(300); | |
} | |
} | |
} | |
// from https://www.woodlandmanufacturing.com/articles/news/how-to-make-a-stranger-things-alphabet-sign-with-lights-code/ | |
void turnOnLetter(String theLetter) | |
{ | |
int lightIndex = letterIndex.indexOf(theLetter); | |
int colorIndexValue = colorLetterIndex.indexOf(theLetter); | |
uint32_t colorValue = colorIndex[colorIndexValue]; | |
leds[lightIndex] = colorValue; | |
} | |
void writeWord(String theword,int letterDuration,int letterSpacing) | |
{ | |
int stringLen = theword.length()+1; | |
char char_array[stringLen]; | |
theword.toCharArray(char_array,stringLen); | |
for(int i=0;i<stringLen-1;i++) | |
{ | |
displayLetter(String(char_array[i]),letterDuration); | |
delay(letterSpacing); | |
} | |
} | |
void displayLetter(String theLetter,int letterDuration) | |
{ | |
int lightIndex = letterIndex.indexOf(theLetter); | |
int colorIndexValue = colorLetterIndex.indexOf(theLetter); | |
uint32_t colorValue = colorIndex[colorIndexValue]; | |
lightLED(lightIndex,colorValue,letterDuration); | |
} | |
void lightLED(int ledIndex,uint32_t colorValue,int duration) | |
{ | |
// Turn the LED on, then pause | |
leds[ledIndex] = colorValue; | |
FastLED.show(); | |
delay(duration); | |
// Now turn the LED off, then pause | |
leds[ledIndex] = CRGB::Black; | |
FastLED.show(); | |
} | |
void flickerLeds(int numTimes) | |
{ | |
for ( int i=0;i<numTimes;i++) | |
{ | |
flicker(); | |
} | |
} | |
void allToFullBright() | |
{ | |
int stringLen = letterIndex.length()+1; | |
char char_array[stringLen]; | |
letterIndex.toCharArray(char_array,stringLen); | |
for(int i=0;i<stringLen-1;i++) | |
{ | |
if ( String(char_array[i]) != "-" ) | |
{ | |
leds[i].maximizeBrightness(); | |
} | |
} | |
FastLED.show(); | |
} | |
void flicker() { //-m9-FLICKER EFFECT | |
int random_bright = random(0,255); | |
int random_delay = random(10,100); | |
int randomFullLight = random(0,2); | |
int stringLen = letterIndex.length()+1; | |
char char_array[stringLen]; | |
letterIndex.toCharArray(char_array,stringLen); | |
for(int i=0;i<stringLen-1;i++) | |
{ | |
if ( String(char_array[i]) != "-" ) | |
{ | |
if ( randomFullLight == 0 ) | |
{ | |
leds[i].maximizeBrightness(); | |
} | |
leds[i].fadeLightBy(random_bright); | |
} | |
} | |
FastLED.show(); | |
delay(random_delay); | |
} | |
//https://www.tweaking4all.com/hardware/arduino/adruino-led-strip-effects/#LEDStripEffectStrobe | |
void Strobe(byte red, byte green, byte blue, int StrobeCount, int FlashDelay, int EndPause){ | |
for(int j = 0; j < StrobeCount; j++) { | |
setAll(red,green,blue); | |
showStrip(); | |
delay(FlashDelay); | |
setAll(0,0,0); | |
showStrip(); | |
delay(FlashDelay); | |
} | |
delay(EndPause); | |
} | |
void showStrip() { | |
#ifdef ADAFRUIT_NEOPIXEL_H | |
// NeoPixel | |
strip.show(); | |
#endif | |
#ifndef ADAFRUIT_NEOPIXEL_H | |
// FastLED | |
FastLED.show(); | |
#endif | |
} | |
void setPixel(int Pixel, byte red, byte green, byte blue) { | |
#ifdef ADAFRUIT_NEOPIXEL_H | |
// NeoPixel | |
strip.setPixelColor(Pixel, strip.Color(red, green, blue)); | |
#endif | |
#ifndef ADAFRUIT_NEOPIXEL_H | |
// FastLED | |
leds[Pixel].r = red; | |
leds[Pixel].g = green; | |
leds[Pixel].b = blue; | |
#endif | |
} | |
void setAll(byte red, byte green, byte blue) { | |
for(int i = 0; i < NUM_LEDS; i++ ) { | |
setPixel(i, red, green, blue); | |
} | |
showStrip(); | |
} | |
//resources | |
//https://www.tweaking4all.com/hardware/arduino/adruino-led-strip-effects |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment