Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //include FastLED library
- #include <FastLED.h>
- //LED Constants
- #define NUM_LEDS 26
- #define COLOR_ORDER RGB
- #define DATA_PIN 6
- CRGB leds[NUM_LEDS];
- /*
- variables for loops and switches
- the main switch case is defaulted to start at 6 to trigger normal lights as the first action
- by variable z initialized at 6
- */
- int y = 1;
- int z = 6;
- int w = 5;
- int i = 20;
- int a = 0;
- int t = 0;
- int h = 0;
- int trans = 0;
- void setup() {
- //add LEDs
- FastLED.addLeds<WS2811, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS);
- //Randomizes the random function so it doesn't pick the same random values every time
- randomSeed(analogRead(0));
- }
- void loop() {
- //main routine
- LIGHTSROUTINE();
- }
- void LIGHTSROUTINE() {
- /*
- main switch case:
- each case is a spooky message followed by the normal lights and ended with a light transition to the next case
- the next case is determined by a random selected value between 0 and 6 with the normal lights function being the default case
- which should be selected for values 5 and 6
- */
- switch (z) {
- case 0:
- IMHERE();
- NORMALLIGHTS();
- TRANSITION();
- break;
- case 1:
- RUN();
- NORMALLIGHTS();
- TRANSITION();
- break;
- case 2:
- HELPME();
- NORMALLIGHTS();
- TRANSITION();
- break;
- case 3:
- LOWREDUP();
- LOWREDDOWN();
- LOWREDUP();
- //transition from red lights needed a seperate function
- REDTRANSITION();
- NORMALLIGHTS();
- TRANSITION();
- break;
- case 4:
- MERRYXMASMOM();
- NORMALLIGHTS();
- TRANSITION();
- break;
- default:
- NORMALLIGHTS();
- TRANSITION();
- break;
- }
- //selects a new value for z randomly after each sub-routine completes
- z = random (0, 6);
- }
- void NORMALLIGHTS() {
- FastLED.clear();
- //reduced the brightness of the LEDs globally to make the box easier to look at when they are all lit
- FastLED.setBrightness(55);
- //call all lights on with their correct colors, then show
- leds[18] = CRGB::White;
- leds[19] = CRGB::Blue;
- leds[20] = CRGB::Purple;
- leds[21] = CRGB::Cyan;
- leds[22] = CRGB::White;
- leds[23] = CRGB::Gold;
- leds[24] = CRGB::Orchid;
- leds[25] = CRGB::Cyan;
- leds[17] = CRGB::Cyan;
- leds[16] = CRGB::Purple;
- leds[15] = CRGB::Blue;
- leds[14] = CRGB::Cyan;
- leds[13] = CRGB::Gold;
- leds[12] = CRGB::Orchid;
- leds[11] = CRGB::Purple;
- leds[10] = CRGB::White;
- leds[9] = CRGB::Purple;
- leds[0] = CRGB::White;
- leds[1] = CRGB::Yellow;
- leds[2] = CRGB::Gold;
- leds[3] = CRGB::Blue;
- leds[4] = CRGB::Orchid;
- leds[5] = CRGB::Blue;
- leds[6] = CRGB::Gold;
- leds[7] = CRGB::Orchid;
- leds[8] = CRGB::Orchid;
- FastLED.show();
- //duration of the normal lights routine is determined by a random value between 20 and 30 seconds
- t = random(20, 30) * 1000;
- delay(t);
- FastLED.clear();
- }
- /*
- for all of the following sub-routines with words displayed
- the delay of the light being displayed for the digit is randomized between .7 and 3 seconds,
- this made the word being displayed look less robotic during the routines
- the functions call the address in the strip corresponding to the correct letter
- display the letter for a random period in the range, then off for a random period in the range
- increased the delay in between words for readability
- each word displayed ends with a flicker function that flickers the last letter
- in the word before ending the routine
- */
- void MERRYXMASMOM() {
- //display "merry xmas mom"
- FastLED.clear();
- leds[13] = CRGB::Gold; FastLED.show(); t = random(7, 30) * 100;
- delay(t);
- leds[13] = CRGB::Black; FastLED.show(); t = random(7, 30) * 100;
- delay(t);
- leds[22] = CRGB::White; FastLED.show(); t = random(7, 30) * 100;
- delay(t);
- leds[22] = CRGB::Black; FastLED.show(); t = random(7, 30) * 100;
- delay(t);
- leds[0] = CRGB::White; FastLED.show(); t = random(7, 30) * 100;
- delay(t);
- leds[0] = CRGB::Black; FastLED.show(); t = random(7, 30) * 100;
- delay(t);
- leds[0] = CRGB::White; FastLED.show(); t = random(7, 30) * 100;
- delay(t);
- leds[0] = CRGB::Black; FastLED.show(); t = random(7, 30) * 100;
- delay(t);
- leds[7] = CRGB::Orchid; FastLED.show(); t = random(7, 30) * 100;
- delay(t);
- leds[7] = CRGB::Black; FastLED.show();
- //constant 1 second delay between words
- delay(1000);
- leds[6] = CRGB::Gold; FastLED.show(); t = random(7, 30) * 100;
- delay(t);
- leds[6] = CRGB::Black; FastLED.show(); t = random(7, 30) * 100;
- delay(t);
- leds[13] = CRGB::Gold; FastLED.show(); t = random(7, 30) * 100;
- delay(t);
- leds[13] = CRGB::Black; FastLED.show(); t = random(7, 30) * 100;
- delay(t);
- leds[18] = CRGB::White; FastLED.show(); t = random(7, 30) * 100;
- delay(t);
- leds[18] = CRGB::Black; FastLED.show(); t = random(7, 30) * 100;
- delay(t);
- leds[1] = CRGB::Yellow; FastLED.show(); t = random(7, 30) * 100;
- delay(t);
- leds[1] = CRGB::Black; FastLED.show();
- delay(1000);
- leds[13] = CRGB::Gold; FastLED.show(); t = random(7, 30) * 100;
- delay(t);
- leds[13] = CRGB::Black; FastLED.show(); t = random(7, 30) * 100;
- delay(t);
- leds[11] = CRGB::Purple; FastLED.show(); t = random(7, 30) * 100;
- delay(t);
- leds[11] = CRGB::Black; FastLED.show(); t = random(7, 30) * 100;
- delay(t);
- leds[13] = CRGB::Gold; FastLED.show(); t = random(7, 30) * 100;
- delay(t);
- //flickers the last light in the routine before ending routine for extra spookiness
- SPOOKYFLICKER2();
- }
- void HELPME() {
- //display "help me"
- FastLED.clear();
- leds[25] = CRGB::Cyan; FastLED.show(); t = random(7, 30) * 100;
- delay(t);
- leds[25] = CRGB::Black; FastLED.show(); t = random(7, 30) * 100;
- delay(t);
- leds[22] = CRGB::White; FastLED.show(); t = random(7, 30) * 100;
- delay(t);
- leds[22] = CRGB::Black; FastLED.show(); t = random(7, 30) * 100;
- delay(t);
- leds[14] = CRGB::Cyan; FastLED.show(); t = random(7, 30) * 100;
- delay(t);
- leds[14] = CRGB::Black; FastLED.show(); t = random(7, 30) * 100;
- delay(t);
- leds[10] = CRGB::White; FastLED.show(); t = random(7, 30) * 100;
- delay(t);
- leds[10] = CRGB::Black; FastLED.show();
- delay(1000);
- leds[13] = CRGB::Gold; FastLED.show(); t = random(7, 30) * 100;
- delay(t);
- leds[13] = CRGB::Black; FastLED.show(); t = random(7, 30) * 100;
- delay(t);
- leds[22] = CRGB::White; FastLED.show(); t = random(7, 30) * 100;
- delay(t);
- SPOOKYFLICKER4();
- }
- void RUN() {
- //display "run"
- FastLED.clear();
- leds[0] = CRGB::White; FastLED.show(); t = random(7, 30) * 100;
- delay(t);
- leds[0] = CRGB::Black; FastLED.show(); t = random(7, 30) * 100;
- delay(t);
- leds[3] = CRGB::Blue; FastLED.show(); t = random(7, 30) * 100;
- delay(t);
- leds[3] = CRGB::Black; FastLED.show(); t = random(7, 30) * 100;
- delay(t);
- leds[12] = CRGB::Orchid; FastLED.show(); t = random(7, 30) * 100;
- delay(t);
- SPOOKYFLICKER3();
- }
- void IMHERE() {
- //display "I'm here"
- FastLED.clear();
- leds[17] = CRGB::Cyan; FastLED.show(); t = random(7, 30) * 100;
- delay(t);
- leds[17] = CRGB::Black; FastLED.show(); t = random(7, 30) * 100;
- delay(t);
- leds[13] = CRGB::Gold; FastLED.show(); t = random(7, 30) * 100;
- delay(t);
- leds[13] = CRGB::Black; FastLED.show();
- delay(1000);
- leds[25] = CRGB::Cyan; FastLED.show(); t = random(7, 30) * 100;
- delay(t);
- leds[25] = CRGB::Black; FastLED.show(); t = random(7, 30) * 100;
- delay(t);
- leds[22] = CRGB::White; FastLED.show(); t = random(7, 30) * 100;
- delay(t);
- leds[22] = CRGB::Black; FastLED.show(); t = random(7, 30) * 100;
- delay(t);
- leds[0] = CRGB::White; FastLED.show(); t = random(7, 30) * 100;
- delay(t);
- leds[0] = CRGB::Black; FastLED.show(); t = random(7, 30) * 100;
- delay(t);
- leds[22] = CRGB::White; FastLED.show(); t = random(7, 30) * 100;
- delay(t);
- SPOOKYFLICKER4();
- }
- /*
- low red up and down functions display the color red starting at a low brightness and up to a little over half
- includes a seperate set brightness in case this function was called first when the arduino boots, though the
- way it is set up now, it never will call this function first.
- for loop increments through the brightness values and calls then inside the second loop to show for 100ms, then increments to next
- */
- void LOWREDUP() {
- FastLED.setBrightness(55);
- for ( int i = 20; i < 180; 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();
- FastLED.delay(100);
- }
- }
- void LOWREDDOWN() {
- for (int i = 180; 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();
- FastLED.delay(100);
- }
- }
- /*
- this is bad coding for the flicker functions, I could have used a better strobe function
- function calls a random value h for how many times the lights flicker between 4 and 10 times
- the loop turns shows the lights and turns them off at intervals of 25 and 30ms respectively
- */
- void SPOOKYFLICKERNORMAL() {
- h = random(4, 10);
- for (int q = 0; q < h; q++) {
- for (int i = 0; i < 6; i++) {
- leds[18] = CRGB::White;
- leds[19] = CRGB::Blue;
- leds[20] = CRGB::Purple;
- leds[21] = CRGB::Cyan;
- leds[22] = CRGB::White;
- leds[23] = CRGB::Gold;
- leds[24] = CRGB::Orchid;
- leds[25] = CRGB::Cyan;
- leds[17] = CRGB::Cyan;
- leds[16] = CRGB::Purple;
- leds[15] = CRGB::Blue;
- leds[14] = CRGB::Cyan;
- leds[13] = CRGB::Gold;
- leds[12] = CRGB::Orchid;
- leds[11] = CRGB::Purple;
- leds[10] = CRGB::White;
- leds[9] = CRGB::Purple;
- leds[0] = CRGB::White;
- leds[1] = CRGB::Yellow;
- leds[2] = CRGB::Gold;
- leds[3] = CRGB::Blue;
- leds[4] = CRGB::Orchid;
- leds[5] = CRGB::Blue;
- leds[6] = CRGB::Gold;
- leds[7] = CRGB::Orchid;
- leds[8] = CRGB::Orchid;
- }
- FastLED.show();
- delay(25);
- for (int i = 0; i < 6; i++) {
- fill_solid( leds, NUM_LEDS, CRGB::Black);
- }
- FastLED.show();
- delay(30);
- }
- }
- void SPOOKYFLICKERRED() {
- h = random(4, 10);
- for (int q = 0; q < h; q++) {
- for (int i = 0; i < 6; i++) {
- fill_solid( leds, NUM_LEDS, CRGB::Red);
- }
- FastLED.show();
- delay(25);
- for (int i = 0; i < 6; i++) {
- fill_solid( leds, NUM_LEDS, CRGB::Black);
- }
- FastLED.show();
- delay(30);
- }
- delay(100);
- }
- void SPOOKYFLICKER4() {
- h = random(4, 10);
- for (int q = 0; q < h; q++) {
- for (int i = 0; i < 6; i++) {
- leds[22] = CRGB::White;
- }
- FastLED.show();
- delay(25);
- for (int i = 0; i < 6; i++) {
- fill_solid( leds, NUM_LEDS, CRGB::Black);
- }
- FastLED.show();
- delay(30);
- }
- delay(100);
- }
- void SPOOKYFLICKER3() {
- h = random(4, 10);
- for (int q = 0; q < h; q++) {
- for (int i = 0; i < 6; i++) {
- leds[12] = CRGB::Orchid;
- }
- FastLED.show();
- delay(25);
- for (int i = 0; i < 6; i++) {
- fill_solid( leds, NUM_LEDS, CRGB::Black);
- }
- FastLED.show();
- delay(30);
- }
- delay(100);
- }
- void SPOOKYFLICKER2() {
- h = random(4, 10);
- for (int q = 0; q < h; q++) {
- for (int i = 0; i < 6; i++) {
- leds[13] = CRGB::Gold;
- }
- FastLED.show();
- delay(25);
- for (int i = 0; i < 6; i++) {
- fill_solid( leds, NUM_LEDS, CRGB::Black);
- }
- FastLED.show();
- delay(30);
- }
- delay(100);
- }
- /*
- more bad coding for the twinkle functions
- these two functions will randomly black out several of the leds in rapid succession
- resulting in a glitchy looking transition
- there is a more efficient way to do this, but I chose this method because I wanted the
- lights to retain their normal color values when glitching out
- */
- void TwinkleDark(int Count, int SpeedDelay, boolean OnlyOne) {
- for (int q = 0; q < 18; q++) {
- for (int i = 0; i < Count; i++) {
- leds[random(NUM_LEDS)] = CRGB::Black;
- FastLED.show();
- delay(SpeedDelay);
- }
- if (OnlyOne) {
- leds[18] = CRGB::White;
- leds[19] = CRGB::Blue;
- leds[20] = CRGB::Purple;
- leds[21] = CRGB::Cyan;
- leds[22] = CRGB::White;
- leds[23] = CRGB::Gold;
- leds[24] = CRGB::Orchid;
- leds[25] = CRGB::Cyan;
- leds[17] = CRGB::Cyan;
- leds[16] = CRGB::Purple;
- leds[15] = CRGB::Blue;
- leds[14] = CRGB::Cyan;
- leds[13] = CRGB::Gold;
- leds[12] = CRGB::Orchid;
- leds[11] = CRGB::Purple;
- leds[10] = CRGB::White;
- leds[9] = CRGB::Purple;
- leds[0] = CRGB::White;
- leds[1] = CRGB::Yellow;
- leds[2] = CRGB::Gold;
- leds[3] = CRGB::Blue;
- leds[4] = CRGB::Orchid;
- leds[5] = CRGB::Blue;
- leds[6] = CRGB::Gold;
- leds[7] = CRGB::Orchid;
- leds[8] = CRGB::Orchid;
- FastLED.show();
- }
- delay(SpeedDelay);
- }
- }
- void TwinkleRed(int Count, int SpeedDelay, boolean OnlyOne) {
- for (int q = 0; q < 18; q++) {
- for (int i = 0; i < Count; i++) {
- leds[random(NUM_LEDS)] = CRGB::Black;
- FastLED.show();
- delay(SpeedDelay);
- }
- if (OnlyOne) {
- fill_solid(leds, NUM_LEDS, CRGB::Red);
- FastLED.show();
- }
- delay(SpeedDelay);
- }
- }
- /*
- transition functions
- I didn't want the routines to transition away from normal lights the same way every time
- these functions decide randomly between the flicker effect and the twinkle effect for
- transitionng away from the normal lights and the red lights
- the functions call a random trans value from 0 to 10 and decide which transition to
- chose based on whether the number chosen is divisible by 2.
- */
- void TRANSITION() {
- trans = random(0, 10);
- if (trans % 2 == 0) {
- TwinkleDark(NUM_LEDS, 2, true);
- }
- else {
- SPOOKYFLICKERNORMAL();
- delay(500);
- }
- }
- void REDTRANSITION() {
- trans = random(0, 10);
- if (trans % 2 == 0) {
- TwinkleRed(NUM_LEDS, 2, true);
- }
- else {
- SPOOKYFLICKERRED();
- delay(500);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement