Advertisement
Guest User

Stranger Things Shadowbox

a guest
Nov 22nd, 2017
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 14.12 KB | None | 0 0
  1. //include FastLED library
  2. #include <FastLED.h>
  3.  
  4. //LED Constants
  5. #define NUM_LEDS 26
  6. #define COLOR_ORDER RGB
  7. #define DATA_PIN 6
  8. CRGB leds[NUM_LEDS];
  9.  
  10. /*
  11. variables for loops and switches
  12. the main switch case is defaulted to start at 6 to trigger normal lights as the first action
  13. by variable z initialized at 6
  14. */
  15.  
  16. int y = 1;
  17. int z = 6;
  18. int w = 5;
  19. int i = 20;
  20. int a = 0;
  21. int t = 0;
  22. int h = 0;
  23. int trans = 0;
  24.  
  25. void setup() {
  26.   //add LEDs
  27.   FastLED.addLeds<WS2811, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS);
  28.  
  29.   //Randomizes the random function so it doesn't pick the same random values every time
  30.   randomSeed(analogRead(0));
  31. }
  32.  
  33. void loop() {
  34.   //main routine
  35.   LIGHTSROUTINE();
  36. }
  37.  
  38. void LIGHTSROUTINE() {
  39.   /*
  40.    main switch case:
  41.    each case is a spooky message followed by the normal lights and ended with a light transition to the next case
  42.    the next case is determined by a random selected value between 0 and 6 with the normal lights function being the default case
  43.    which should be selected for values 5 and 6
  44.    */
  45.   switch (z) {
  46.     case 0:
  47.       IMHERE();
  48.       NORMALLIGHTS();
  49.       TRANSITION();
  50.       break;
  51.     case 1:
  52.       RUN();
  53.       NORMALLIGHTS();
  54.       TRANSITION();
  55.       break;
  56.     case 2:
  57.       HELPME();
  58.       NORMALLIGHTS();
  59.       TRANSITION();
  60.       break;
  61.     case 3:
  62.       LOWREDUP();
  63.       LOWREDDOWN();
  64.       LOWREDUP();
  65.       //transition from red lights needed a seperate function
  66.       REDTRANSITION();
  67.       NORMALLIGHTS();
  68.       TRANSITION();
  69.       break;
  70.     case 4:
  71.       MERRYXMASMOM();
  72.       NORMALLIGHTS();
  73.       TRANSITION();
  74.       break;
  75.     default:
  76.       NORMALLIGHTS();
  77.       TRANSITION();
  78.       break;
  79.   }
  80.   //selects a new value for z randomly after each sub-routine completes
  81.   z = random (0, 6);
  82. }
  83. void NORMALLIGHTS() {
  84.   FastLED.clear();
  85.   //reduced the brightness of the LEDs globally to make the box easier to look at when they are all lit
  86.   FastLED.setBrightness(55);
  87.  
  88.   //call all lights on with their correct colors, then show
  89.   leds[18] = CRGB::White;
  90.   leds[19] = CRGB::Blue;
  91.   leds[20] = CRGB::Purple;
  92.   leds[21] = CRGB::Cyan;
  93.   leds[22] = CRGB::White;
  94.   leds[23] = CRGB::Gold;
  95.   leds[24] = CRGB::Orchid;
  96.   leds[25] = CRGB::Cyan;
  97.   leds[17] = CRGB::Cyan;
  98.   leds[16] = CRGB::Purple;
  99.   leds[15] = CRGB::Blue;
  100.   leds[14] = CRGB::Cyan;
  101.   leds[13] = CRGB::Gold;
  102.   leds[12] = CRGB::Orchid;
  103.   leds[11] = CRGB::Purple;
  104.   leds[10] = CRGB::White;
  105.   leds[9] = CRGB::Purple;
  106.   leds[0] = CRGB::White;
  107.   leds[1] = CRGB::Yellow;
  108.   leds[2] = CRGB::Gold;
  109.   leds[3] = CRGB::Blue;
  110.   leds[4] = CRGB::Orchid;
  111.   leds[5] = CRGB::Blue;
  112.   leds[6] = CRGB::Gold;
  113.   leds[7] = CRGB::Orchid;
  114.   leds[8] = CRGB::Orchid;
  115.  
  116.   FastLED.show();
  117.  
  118.   //duration of the normal lights routine is determined by a random value between 20 and 30 seconds
  119.   t = random(20, 30) * 1000;
  120.   delay(t);
  121.  
  122.   FastLED.clear();
  123. }
  124.  
  125. /*
  126. for all of the following sub-routines with words displayed
  127. the delay of the light being displayed for the digit is randomized between .7 and 3 seconds,
  128. this made the word being displayed look less robotic during the routines
  129.  
  130. the functions call the address in the strip corresponding to the correct letter
  131. display the letter for a random period in the range, then off for a random period in the range
  132. increased the delay in between words for readability
  133.  
  134. each word displayed ends with a flicker function that flickers the last letter
  135. in the word before ending the routine
  136. */
  137.  
  138. void MERRYXMASMOM() {
  139.   //display "merry xmas mom"
  140.   FastLED.clear();
  141.   leds[13] = CRGB::Gold;   FastLED.show();   t = random(7, 30) * 100;
  142.   delay(t);
  143.   leds[13] = CRGB::Black;  FastLED.show();   t = random(7, 30) * 100;
  144.   delay(t);
  145.   leds[22] = CRGB::White;  FastLED.show();   t = random(7, 30) * 100;
  146.   delay(t);
  147.   leds[22] = CRGB::Black;  FastLED.show();   t = random(7, 30) * 100;
  148.   delay(t);
  149.   leds[0] = CRGB::White;  FastLED.show();   t = random(7, 30) * 100;
  150.   delay(t);
  151.   leds[0] = CRGB::Black;  FastLED.show();   t = random(7, 30) * 100;
  152.   delay(t);
  153.   leds[0] = CRGB::White;  FastLED.show();   t = random(7, 30) * 100;
  154.   delay(t);
  155.   leds[0] = CRGB::Black;  FastLED.show();   t = random(7, 30) * 100;
  156.   delay(t);
  157.   leds[7] = CRGB::Orchid;  FastLED.show();   t = random(7, 30) * 100;
  158.   delay(t);
  159.   leds[7] = CRGB::Black;  FastLED.show();
  160.   //constant 1 second delay between words
  161.   delay(1000);
  162.   leds[6] = CRGB::Gold;  FastLED.show();   t = random(7, 30) * 100;
  163.   delay(t);
  164.   leds[6] = CRGB::Black;  FastLED.show();   t = random(7, 30) * 100;
  165.   delay(t);
  166.   leds[13] = CRGB::Gold;  FastLED.show();   t = random(7, 30) * 100;
  167.   delay(t);
  168.   leds[13] = CRGB::Black;  FastLED.show();   t = random(7, 30) * 100;
  169.   delay(t);
  170.   leds[18] = CRGB::White;  FastLED.show();   t = random(7, 30) * 100;
  171.   delay(t);
  172.   leds[18] = CRGB::Black;  FastLED.show();   t = random(7, 30) * 100;
  173.   delay(t);
  174.   leds[1] = CRGB::Yellow;  FastLED.show();   t = random(7, 30) * 100;
  175.   delay(t);
  176.   leds[1] = CRGB::Black;  FastLED.show();
  177.   delay(1000);
  178.   leds[13] = CRGB::Gold;  FastLED.show();   t = random(7, 30) * 100;
  179.   delay(t);
  180.   leds[13] = CRGB::Black;  FastLED.show();   t = random(7, 30) * 100;
  181.   delay(t);
  182.   leds[11] = CRGB::Purple;  FastLED.show();   t = random(7, 30) * 100;
  183.   delay(t);
  184.   leds[11] = CRGB::Black;  FastLED.show();   t = random(7, 30) * 100;
  185.   delay(t);
  186.   leds[13] = CRGB::Gold;  FastLED.show();   t = random(7, 30) * 100;
  187.   delay(t);
  188.   //flickers the last light in the routine before ending routine for extra spookiness
  189.   SPOOKYFLICKER2();
  190. }
  191.  
  192. void HELPME() {
  193.   //display "help me"
  194.   FastLED.clear();
  195.   leds[25] = CRGB::Cyan;  FastLED.show();   t = random(7, 30) * 100;
  196.   delay(t);
  197.   leds[25] = CRGB::Black;  FastLED.show();   t = random(7, 30) * 100;
  198.   delay(t);
  199.   leds[22] = CRGB::White;  FastLED.show();   t = random(7, 30) * 100;
  200.   delay(t);
  201.   leds[22] = CRGB::Black;  FastLED.show();   t = random(7, 30) * 100;
  202.   delay(t);
  203.   leds[14] = CRGB::Cyan;  FastLED.show();   t = random(7, 30) * 100;
  204.   delay(t);
  205.   leds[14] = CRGB::Black;  FastLED.show();   t = random(7, 30) * 100;
  206.   delay(t);
  207.   leds[10] = CRGB::White;  FastLED.show();   t = random(7, 30) * 100;
  208.   delay(t);
  209.   leds[10] = CRGB::Black;  FastLED.show();
  210.   delay(1000);
  211.   leds[13] = CRGB::Gold;  FastLED.show();   t = random(7, 30) * 100;
  212.   delay(t);
  213.   leds[13] = CRGB::Black;  FastLED.show();   t = random(7, 30) * 100;
  214.   delay(t);
  215.   leds[22] = CRGB::White;  FastLED.show();   t = random(7, 30) * 100;
  216.   delay(t);
  217.   SPOOKYFLICKER4();
  218. }
  219.  
  220. void RUN() {
  221.   //display "run"
  222.   FastLED.clear();
  223.   leds[0] = CRGB::White;  FastLED.show();   t = random(7, 30) * 100;
  224.   delay(t);
  225.   leds[0] = CRGB::Black;  FastLED.show();   t = random(7, 30) * 100;
  226.   delay(t);
  227.   leds[3] = CRGB::Blue;  FastLED.show();   t = random(7, 30) * 100;
  228.   delay(t);
  229.   leds[3] = CRGB::Black;  FastLED.show();   t = random(7, 30) * 100;
  230.   delay(t);
  231.   leds[12] = CRGB::Orchid;  FastLED.show();   t = random(7, 30) * 100;
  232.   delay(t);
  233.   SPOOKYFLICKER3();
  234. }
  235.  
  236. void IMHERE() {
  237.   //display "I'm here"
  238.   FastLED.clear();
  239.   leds[17] = CRGB::Cyan;  FastLED.show();   t = random(7, 30) * 100;
  240.   delay(t);
  241.   leds[17] = CRGB::Black;  FastLED.show();   t = random(7, 30) * 100;
  242.   delay(t);
  243.   leds[13] = CRGB::Gold;  FastLED.show();   t = random(7, 30) * 100;
  244.   delay(t);
  245.   leds[13] = CRGB::Black;  FastLED.show();
  246.   delay(1000);
  247.   leds[25] = CRGB::Cyan;  FastLED.show();   t = random(7, 30) * 100;
  248.   delay(t);
  249.   leds[25] = CRGB::Black;  FastLED.show();   t = random(7, 30) * 100;
  250.   delay(t);
  251.   leds[22] = CRGB::White;  FastLED.show();   t = random(7, 30) * 100;
  252.   delay(t);
  253.   leds[22] = CRGB::Black;  FastLED.show();   t = random(7, 30) * 100;
  254.   delay(t);
  255.   leds[0] = CRGB::White;  FastLED.show();   t = random(7, 30) * 100;
  256.   delay(t);
  257.   leds[0] = CRGB::Black;  FastLED.show();   t = random(7, 30) * 100;
  258.   delay(t);
  259.   leds[22] = CRGB::White;  FastLED.show();   t = random(7, 30) * 100;
  260.   delay(t);
  261.   SPOOKYFLICKER4();
  262. }
  263.  
  264. /*
  265. low red up and down functions display the color red starting at a low brightness and up to a little over half
  266. includes a seperate set brightness in case this function was called first when the arduino boots, though the
  267. way it is set up now, it never will call this function first.
  268.  
  269. for loop increments through the brightness values and calls then inside the second loop to show for 100ms, then increments to next
  270.  */
  271. void LOWREDUP() {
  272.   FastLED.setBrightness(55);
  273.   for ( int i = 20; i < 180; i = i + y ) {
  274.  
  275.     int r = i;
  276.     int b = 0;
  277.     int g = 0;
  278.  
  279.     for (int x = 0; x < NUM_LEDS; x++) {
  280.       leds[x] = CRGB(r, g, b);
  281.     }
  282.  
  283.     FastLED.show();
  284.     FastLED.delay(100);
  285.   }
  286. }
  287. void LOWREDDOWN() {
  288.   for (int i = 180; i > 20; i = i - y) {
  289.  
  290.     int r = i;
  291.     int b = 0;
  292.     int g = 0;
  293.  
  294.     for (int x = 0; x < NUM_LEDS; x++) {
  295.       leds[x] = CRGB(r, g, b);
  296.     }
  297.  
  298.     FastLED.show();
  299.     FastLED.delay(100);
  300.   }
  301. }
  302.  
  303. /*
  304. this is bad coding for the flicker functions, I could have used a better strobe function
  305. function calls a random value h for how many times the lights flicker between 4 and 10 times
  306.  
  307. the loop turns shows the lights and turns them off at intervals of 25 and 30ms respectively
  308.  */
  309. void SPOOKYFLICKERNORMAL() {
  310.   h = random(4, 10);
  311.   for (int q = 0; q < h; q++) {
  312.     for (int i = 0; i < 6; i++) {
  313.       leds[18] = CRGB::White;
  314.       leds[19] = CRGB::Blue;
  315.       leds[20] = CRGB::Purple;
  316.       leds[21] = CRGB::Cyan;
  317.       leds[22] = CRGB::White;
  318.       leds[23] = CRGB::Gold;
  319.       leds[24] = CRGB::Orchid;
  320.       leds[25] = CRGB::Cyan;
  321.       leds[17] = CRGB::Cyan;
  322.       leds[16] = CRGB::Purple;
  323.       leds[15] = CRGB::Blue;
  324.       leds[14] = CRGB::Cyan;
  325.       leds[13] = CRGB::Gold;
  326.       leds[12] = CRGB::Orchid;
  327.       leds[11] = CRGB::Purple;
  328.       leds[10] = CRGB::White;
  329.       leds[9] = CRGB::Purple;
  330.       leds[0] = CRGB::White;
  331.       leds[1] = CRGB::Yellow;
  332.       leds[2] = CRGB::Gold;
  333.       leds[3] = CRGB::Blue;
  334.       leds[4] = CRGB::Orchid;
  335.       leds[5] = CRGB::Blue;
  336.       leds[6] = CRGB::Gold;
  337.       leds[7] = CRGB::Orchid;
  338.       leds[8] = CRGB::Orchid;
  339.     }
  340.     FastLED.show();
  341.     delay(25);
  342.     for (int i = 0; i < 6; i++) {
  343.       fill_solid( leds, NUM_LEDS, CRGB::Black);
  344.     }
  345.     FastLED.show();
  346.     delay(30);
  347.   }
  348. }
  349.  
  350. void SPOOKYFLICKERRED() {
  351.   h = random(4, 10);
  352.   for (int q = 0; q < h; q++) {
  353.     for (int i = 0; i < 6; i++) {
  354.  
  355.       fill_solid( leds, NUM_LEDS, CRGB::Red);
  356.     }
  357.     FastLED.show();
  358.     delay(25);
  359.     for (int i = 0; i < 6; i++) {
  360.       fill_solid( leds, NUM_LEDS, CRGB::Black);
  361.     }
  362.     FastLED.show();
  363.     delay(30);
  364.   }
  365.   delay(100);
  366. }
  367.  
  368. void SPOOKYFLICKER4() {
  369.   h = random(4, 10);
  370.   for (int q = 0; q < h; q++) {
  371.     for (int i = 0; i < 6; i++) {
  372.  
  373.       leds[22] = CRGB::White;
  374.     }
  375.     FastLED.show();
  376.     delay(25);
  377.     for (int i = 0; i < 6; i++) {
  378.       fill_solid( leds, NUM_LEDS, CRGB::Black);
  379.     }
  380.     FastLED.show();
  381.     delay(30);
  382.   }
  383.   delay(100);
  384. }
  385.  
  386. void SPOOKYFLICKER3() {
  387.   h = random(4, 10);
  388.   for (int q = 0; q < h; q++) {
  389.     for (int i = 0; i < 6; i++) {
  390.  
  391.       leds[12] = CRGB::Orchid;
  392.     }
  393.     FastLED.show();
  394.     delay(25);
  395.     for (int i = 0; i < 6; i++) {
  396.       fill_solid( leds, NUM_LEDS, CRGB::Black);
  397.     }
  398.     FastLED.show();
  399.     delay(30);
  400.   }
  401.   delay(100);
  402. }
  403.  
  404. void SPOOKYFLICKER2() {
  405.   h = random(4, 10);
  406.   for (int q = 0; q < h; q++) {
  407.     for (int i = 0; i < 6; i++) {
  408.  
  409.       leds[13] = CRGB::Gold;
  410.     }
  411.     FastLED.show();
  412.     delay(25);
  413.     for (int i = 0; i < 6; i++) {
  414.       fill_solid( leds, NUM_LEDS, CRGB::Black);
  415.     }
  416.     FastLED.show();
  417.     delay(30);
  418.   }
  419.   delay(100);
  420. }
  421.  
  422. /*
  423. more bad coding for the twinkle functions
  424.  
  425. these two functions will randomly black out several of the leds in rapid succession
  426. resulting in a glitchy looking transition
  427.  
  428. there is a more efficient way to do this, but I chose this method because I wanted the
  429. lights to retain their normal color values when glitching out
  430.  */
  431. void TwinkleDark(int Count, int SpeedDelay, boolean OnlyOne) {
  432.  
  433.   for (int q = 0; q < 18; q++) {
  434.     for (int i = 0; i < Count; i++) {
  435.       leds[random(NUM_LEDS)] = CRGB::Black;
  436.       FastLED.show();
  437.       delay(SpeedDelay);
  438.     }
  439.     if (OnlyOne) {
  440.       leds[18] = CRGB::White;
  441.       leds[19] = CRGB::Blue;
  442.       leds[20] = CRGB::Purple;
  443.       leds[21] = CRGB::Cyan;
  444.       leds[22] = CRGB::White;
  445.       leds[23] = CRGB::Gold;
  446.       leds[24] = CRGB::Orchid;
  447.       leds[25] = CRGB::Cyan;
  448.       leds[17] = CRGB::Cyan;
  449.       leds[16] = CRGB::Purple;
  450.       leds[15] = CRGB::Blue;
  451.       leds[14] = CRGB::Cyan;
  452.       leds[13] = CRGB::Gold;
  453.       leds[12] = CRGB::Orchid;
  454.       leds[11] = CRGB::Purple;
  455.       leds[10] = CRGB::White;
  456.       leds[9] = CRGB::Purple;
  457.       leds[0] = CRGB::White;
  458.       leds[1] = CRGB::Yellow;
  459.       leds[2] = CRGB::Gold;
  460.       leds[3] = CRGB::Blue;
  461.       leds[4] = CRGB::Orchid;
  462.       leds[5] = CRGB::Blue;
  463.       leds[6] = CRGB::Gold;
  464.       leds[7] = CRGB::Orchid;
  465.       leds[8] = CRGB::Orchid;
  466.  
  467.       FastLED.show();
  468.     }
  469.     delay(SpeedDelay);
  470.   }
  471. }
  472.  
  473. void TwinkleRed(int Count, int SpeedDelay, boolean OnlyOne) {
  474.  
  475.   for (int q = 0; q < 18; q++) {
  476.     for (int i = 0; i < Count; i++) {
  477.       leds[random(NUM_LEDS)] = CRGB::Black;
  478.       FastLED.show();
  479.       delay(SpeedDelay);
  480.     }
  481.     if (OnlyOne) {
  482.       fill_solid(leds, NUM_LEDS, CRGB::Red);
  483.  
  484.       FastLED.show();
  485.     }
  486.     delay(SpeedDelay);
  487.   }
  488. }
  489.  
  490. /*
  491. transition functions
  492. I didn't want the routines to transition away from normal lights the same way every time
  493. these functions decide randomly between the flicker effect and the twinkle effect for
  494. transitionng away from the normal lights and the red lights
  495.  
  496. the functions call a random trans value from 0 to 10 and decide which transition to
  497. chose based on whether the number chosen is divisible by 2.
  498.  */
  499. void TRANSITION() {
  500.   trans = random(0, 10);
  501.   if (trans % 2 == 0) {
  502.     TwinkleDark(NUM_LEDS, 2, true);
  503.   }
  504.   else {
  505.     SPOOKYFLICKERNORMAL();
  506.     delay(500);
  507.   }
  508. }
  509.  
  510.  
  511. void REDTRANSITION() {
  512.   trans = random(0, 10);
  513.   if (trans % 2 == 0) {
  514.     TwinkleRed(NUM_LEDS, 2, true);
  515.   }
  516.   else {
  517.     SPOOKYFLICKERRED();
  518.     delay(500);
  519.   }
  520. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement