#include <FastLED.h>
#define DATA_PIN 6 //this is the data pin connected to the LED strip. If using WS2801 you also need a clock pin
#define NUM_LEDS 50 //change this for the number of LEDs in the strip
#define COLOR_ORDER GRB

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;

void setup() {
  FastLED.addLeds<WS2811, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS); //setting up the FastLED
  randomSeed(analogRead(0)); //seeding my random numbers to make it more random. If you just use the random function it will repeat the same pattern every time it is loaded.
}

void loop() {

  //The switch case loop let me use a random number generator to switch between subroutines. The default case is run if the condition isn't met in any other case. Since I wanted the standard christmas lights more often
  //than everything else, I have 3 conditions that will give me the christmas lights (z=6, z=7, z=8) while there is only one condition for all other subroutines.

  switch (z) {
    case 0:
      IMHERE();
      break;
    case 1:
      RUN();
      break;
    case 2:
      HELP();
      break;
    case 3:
      //I broke case 3 and case 5 into two routines, one to go up and one to go down. When I had it as a for loop that went up and down the program got stuck in a never ending loop and didn't leave the subroutine
      LOWREDUP();
      LOWREDDOWN();
      LOWREDUP();
      LOWREDDOWN();
      break;
    case 4:
      BLACKOUT();
      break;
    case 5:
      glowup();
      glowdown();
      glowup();
      glowdown();
      break;
    default:
      CHRISTMAS();
      break;
  }
  z = random (0, 9); //random includes the first number and maxes out at one less than the second number
}
//All of my subroutines are below. I've been told that this is very poor coding, but I'm new to all of this. Feel free to replace my subroutines with ones of your own. Many people have suggested using strings instead of
//hard writing each of the LED conditions like I have below.
void CHRISTMAS() {
  CRGB const xmas_colours[] = {
    CRGB (0, 255, 255), //aqua
    CRGB (153, 50, 204), //dark orchid
    CRGB (255, 255, 0), //yellow
    CRGB (0, 255, 127), //spring green
    CRGB (255, 165, 0), //orange
    CRGB (65, 105, 255), //royal blue
    CRGB (76, 0, 153), //dark purple
    CRGB (255, 105, 180), //hot pink
    CRGB (0, 128, 0), //dark green
    CRGB (255, 0, 0), //red
  };
  FastLED.clear();
  for (int x = 0; x < NUM_LEDS; x++) {
    leds[x] = xmas_colours[x % 10];
  }
  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 IMHERE() {
  //These are all where strings would have been better. I'm going to work on a rev2 so we'll see what happens. Suggestions are appreciated
  FastLED.clear();
  leds[84 % NUM_LEDS] = CRGB (255, 255, 255);
  leds[85 % NUM_LEDS] = CRGB (255, 255, 255);
  leds[86 % NUM_LEDS] = CRGB (255, 255, 255);
  FastLED.show();
  delay(2000);
  leds[84 % NUM_LEDS] = CRGB (0, 0, 0);
  leds[85 % NUM_LEDS] = CRGB (0, 0, 0);
  leds[86 % NUM_LEDS] = CRGB (0, 0, 0);
  FastLED.show();
  delay(500);
  leds[95 % NUM_LEDS] = CRGB (255, 255, 255);
  leds[96 % NUM_LEDS] = CRGB (255, 255, 255);
  FastLED.show();
  delay(2000);
  leds[95 % NUM_LEDS] = CRGB (0, 0, 0);
  leds[96 % NUM_LEDS] = CRGB (0, 0, 0);
  FastLED.show();
  delay(500);
  leds[82 % NUM_LEDS] = CRGB (255, 255, 255);
  leds[83 % NUM_LEDS] = CRGB (255, 255, 255);
  FastLED.show();
  delay(2000);
  leds[82 % NUM_LEDS] = CRGB (0, 0, 0);
  leds[83 % NUM_LEDS] = CRGB (0, 0, 0);
  FastLED.show();
  delay(500);
  leds[73 % NUM_LEDS] = CRGB (255, 255, 255);
  leds[74 % NUM_LEDS] = CRGB (255, 255, 255);
  leds[75 % NUM_LEDS] = CRGB (255, 255, 255);
  FastLED.show();
  delay(2000);
  leds[73 % NUM_LEDS] = CRGB (0, 0, 0);
  leds[74 % NUM_LEDS] = CRGB (0, 0, 0);
  leds[75 % NUM_LEDS] = CRGB (0, 0, 0);
  FastLED.show();
  delay(500);
  leds[33 % NUM_LEDS] = CRGB (255, 255, 255);
  leds[34 % NUM_LEDS] = CRGB (255, 255, 255);
  FastLED.show();
  delay(2000);
  leds[33 % NUM_LEDS] = CRGB (0, 0, 0);
  leds[34 % NUM_LEDS] = CRGB (0, 0, 0);
  FastLED.show();
  delay(500);
  leds[73 % NUM_LEDS] = CRGB (255, 255, 255);
  leds[74 % NUM_LEDS] = CRGB (255, 255, 255);
  leds[75 % NUM_LEDS] = CRGB (255, 255, 255);
  FastLED.show();
  delay(2000);
  leds[73 % NUM_LEDS] = CRGB (0, 0, 0);
  leds[74 % NUM_LEDS] = CRGB (0, 0, 0);
  leds[75 % NUM_LEDS] = CRGB (0, 0, 0);
  FastLED.show();
  delay(500);
  leds[84 % NUM_LEDS] = CRGB (255, 255, 255);
  leds[85 % NUM_LEDS] = CRGB (255, 255, 255);
  leds[86 % NUM_LEDS] = CRGB (255, 255, 255);
  leds[95 % NUM_LEDS] = CRGB (255, 255, 255);
  leds[96 % NUM_LEDS] = CRGB (255, 255, 255);
  leds[82 % NUM_LEDS] = CRGB (255, 255, 255);
  leds[83 % NUM_LEDS] = CRGB (255, 255, 255);
  leds[73 % NUM_LEDS] = CRGB (255, 255, 255);
  leds[74 % NUM_LEDS] = CRGB (255, 255, 255);
  leds[75 % NUM_LEDS] = CRGB (255, 255, 255);
  leds[33 % NUM_LEDS] = CRGB (255, 255, 255);
  leds[34 % NUM_LEDS] = CRGB (255, 255, 255);
  FastLED.show();
  delay(500);
  FastLED.clear();
  delay(500);
  leds[84 % NUM_LEDS] = CRGB (255, 255, 255);
  leds[85 % NUM_LEDS] = CRGB (255, 255, 255);
  leds[86 % NUM_LEDS] = CRGB (255, 255, 255);
  leds[95 % NUM_LEDS] = CRGB (255, 255, 255);
  leds[96 % NUM_LEDS] = CRGB (255, 255, 255);
  leds[82 % NUM_LEDS] = CRGB (255, 255, 255);
  leds[83 % NUM_LEDS] = CRGB (255, 255, 255);
  leds[73 % NUM_LEDS] = CRGB (255, 255, 255);
  leds[74 % NUM_LEDS] = CRGB (255, 255, 255);
  leds[75 % NUM_LEDS] = CRGB (255, 255, 255);
  leds[33 % NUM_LEDS] = CRGB (255, 255, 255);
  leds[34 % NUM_LEDS] = CRGB (255, 255, 255);
  FastLED.show();
  delay(200);
  FastLED.clear();
  delay(300);
  leds[84 % NUM_LEDS] = CRGB (255, 255, 255);
  leds[85 % NUM_LEDS] = CRGB (255, 255, 255);
  leds[86 % NUM_LEDS] = CRGB (255, 255, 255);
  leds[95 % NUM_LEDS] = CRGB (255, 255, 255);
  leds[96 % NUM_LEDS] = CRGB (255, 255, 255);
  leds[82 % NUM_LEDS] = CRGB (255, 255, 255);
  leds[83 % NUM_LEDS] = CRGB (255, 255, 255);
  leds[73 % NUM_LEDS] = CRGB (255, 255, 255);
  leds[74 % NUM_LEDS] = CRGB (255, 255, 255);
  leds[75 % NUM_LEDS] = CRGB (255, 255, 255);
  leds[33 % NUM_LEDS] = CRGB (255, 255, 255);
  leds[34 % NUM_LEDS] = CRGB (255, 255, 255);
  FastLED.show();
  delay(10000);
  FastLED.clear();
}

void RUN() {
  FastLED.clear();
  leds[33] = CRGB (255, 255, 255);
  leds[34] = CRGB (255, 255, 255);
  FastLED.show();
  delay(500);
  leds[33] = CRGB (0, 0, 0);
  leds[34] = CRGB (0, 0, 0);
  FastLED.show();
  delay(500);
  leds[33] = CRGB (255, 255, 255);
  leds[34] = CRGB (255, 255, 255);
  FastLED.show();
  delay(300);
  leds[33] = CRGB (0, 0, 0);
  leds[34] = CRGB (0, 0, 0);
  FastLED.show();
  delay(600);
  leds[33] = CRGB (255, 255, 255);
  leds[34] = CRGB (255, 255, 255);
  FastLED.show();
  delay(400);
  leds[33] = CRGB (0, 0, 0);
  leds[34] = CRGB (0, 0, 0);
  FastLED.show();
  delay(500);
  leds[33] = CRGB (255, 255, 255);
  leds[34] = CRGB (255, 255, 255);
  FastLED.show();
  delay(2000);
  leds[23] = CRGB (255, 255, 255);
  leds[24] = CRGB (255, 255, 255);
  FastLED.show();
  delay(2000);
  leds[45] = CRGB (255, 255, 255);
  leds[46] = CRGB (255, 255, 255);
  FastLED.show();
  delay(10000);
  leds[34] = CRGB (0, 0, 0);
  FastLED.show();
  delay(300);
  leds[45] = CRGB (0, 0, 0);
  FastLED.show();
  delay(500);
  leds[23] = CRGB (0, 0, 0);
  FastLED.show();
  delay(1000);
  leds[46] = CRGB (0, 0, 0);
  FastLED.show();
  delay(2000);
  leds[33] = CRGB (0, 0, 0);
  FastLED.show();
  delay(300);
  leds[24] = CRGB (0, 0, 0);
  FastLED.show();
  delay(5000);
  FastLED.clear();
}

void HELP() {
  FastLED.clear();
  leds[82 % NUM_LEDS] = CRGB (255, 255, 255);
  leds[83 % NUM_LEDS] = CRGB (255, 255, 255);
  FastLED.show();
  delay(500);
  leds[82 % NUM_LEDS] = CRGB (0, 0, 0);
  leds[83 % NUM_LEDS] = CRGB (0, 0, 0);
  FastLED.show();
  delay(700);
  leds[82 % NUM_LEDS] = CRGB (255, 255, 255);
  leds[83 % NUM_LEDS] = CRGB (255, 255, 255);
  FastLED.show();
  delay(400);
  leds[82 % NUM_LEDS] = CRGB (0, 0, 0);
  leds[83 % NUM_LEDS] = CRGB (0, 0, 0);
  FastLED.show();
  delay(400);
  leds[82 % NUM_LEDS] = CRGB (255, 255, 255);
  leds[83 % NUM_LEDS] = CRGB (255, 255, 255);
  FastLED.show();
  delay(250);
  leds[82 % NUM_LEDS] = CRGB (0, 0, 0);
  leds[83 % NUM_LEDS] = CRGB (0, 0, 0);
  FastLED.show();
  delay(250);
  leds[82 % NUM_LEDS] = CRGB (255, 255, 255);
  leds[83 % NUM_LEDS] = CRGB (255, 255, 255);
  FastLED.show();
  delay(2000);
  leds[73 % NUM_LEDS] = CRGB (255, 255, 255);
  leds[74 % NUM_LEDS] = CRGB (255, 255, 255);
  leds[75 % NUM_LEDS] = CRGB (255, 255, 255);
  FastLED.show();
  delay(2000);
  leds[93 % NUM_LEDS] = CRGB (255, 255, 255);
  FastLED.show();
  delay(2000);
  leds[38 % NUM_LEDS] = CRGB (255, 255, 255);
  leds[39 % NUM_LEDS] = CRGB (255, 255, 255);
  FastLED.show();
  delay(2000);
  leds[38 % NUM_LEDS] = CRGB (0, 0, 0);
  leds[39 % NUM_LEDS] = CRGB (0, 0, 0);
  FastLED.show();
  delay(1000);
  leds[38 % NUM_LEDS] = CRGB (255, 255, 255);
  leds[39 % NUM_LEDS] = CRGB (255, 255, 255);
  FastLED.show();
  delay(500);
  leds[38 % NUM_LEDS] = CRGB (0, 0, 0);
  leds[39 % NUM_LEDS] = CRGB (0, 0, 0);
  FastLED.show();
  delay(200);
  leds[38 % NUM_LEDS] = CRGB (255, 255, 255);
  leds[39 % NUM_LEDS] = CRGB (255, 255, 255);
  FastLED.show();
  delay(200);
  leds[38 % NUM_LEDS] = CRGB (0, 0, 0);
  leds[39 % NUM_LEDS] = CRGB (0, 0, 0);
  FastLED.show();
  delay(200);
  leds[38 % NUM_LEDS] = CRGB (255, 255, 255);
  leds[39 % NUM_LEDS] = CRGB (255, 255, 255);
  FastLED.show();
  delay(10000);
  FastLED.clear();
  delay(5000);
}

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);

}