//NOTES 3rd OCTAVE
//NATURALS
#define cTH 130.81
#define dTH 146.83
#define eTH 164.81
#define fTH 174.61
#define gTH 196
#define aTH 220
#define bTH 246.94
//SHARPS OR FLATS
#define csTH 138.59
#define dsTH 155.56
#define fsTH 185
#define gsTH 207.65
#define asTH 233.08
//4TH NATURALS
#define c 261.63
#define d 293.66
#define e 329.63
#define f 349.23
#define g 392
#define a 440
#define b 493.88
//SHARPS OR FLATS
#define cs 277.18
#define ds 311.13
#define fs 369.99
#define gs 415.30
#define as 466.2
//5TH NATURALS
#define cF 523.3
#define dF 587.4
#define eF 659.3
#define fF 698.5
#define gF 784
#define aF 880
#define bF 987.8
//SHARPS OR FLATS
#define csF 554.4
#define dsF 622.3
#define fsF 740
#define gsF 830.6
#define asF 932.3
//No Sound
#define NT  0
// LIGHTS
//END
int buzzer = 23;
//ARRAYS
//LIGHTS
//Song One
int songOne   [] = {gTH,c,c ,d ,c ,bTH,aTH,aTH,aTH,d,d,e ,d ,c ,bTH,gTH,gTH,e,e ,f ,e ,d ,c,aTH,NT,aTH,gTH,aTH,d,bTH,c,NT,gTH,c,c,c,bTH,bTH,c,bTH,aTH,gTH,gTH,e,e,d,c ,d ,g ,gTH,gTH,gTH,aTH,d,bTH,c};
int delayOne  [] = {4  ,4,12,12,12,12 ,4  ,4  ,4  ,4,8,12,12,12,4  ,4  ,4  ,4,12,12,12,12,4,4  ,32,12 ,4  ,4  ,4,4  ,2,8 ,2  ,4,4,4,2  ,4  ,4,4  ,4  ,2  ,4  ,4,4,8,12,12,4 ,4  ,12 ,12 ,4  ,4,4  ,4};
int sizeofSong = 56;

void setup() 
{
  for(int i = 0 ; i <= 23 ; i++)
  {
    pinMode(i , OUTPUT);
  }
}

void loop() 
{
  blink6();
  ledOn();
  delay(1000);
  blink1();
  ledOff();
  delay(100);
  blink2();
  ledOff();
  delay(100);
  blink3();
  ledOff();
  delay(100);
  blink4();
  ledOff();
  delay(100);
}

void song1()
{
for(int thisNote = 0 ; thisNote < 56 ; thisNote++)
    {

    int noteDura = 1800/ delayOne[thisNote];

    tone(buzzer, songOne[thisNote], noteDura);
  
    ledOn();


    delay(noteDura);
    ledOff();

    int pauseBetweenNotes = noteDura * 0.30;
    delay(pauseBetweenNotes);

    noTone(buzzer);
    }
}

void ledOn()
{
  for (int i = 0 ; i <= 19 ; i++) 
  {
    digitalWrite(i,1);
  }
}
void ledOff()
{
  for (int i = 0 ; i <= 19 ; i++) 
    {
    digitalWrite(i,0);
    }
}

void blink1()
{
  for (int z = 1;z <= 3 ;z++)
  {
    for(int i = 19 ; i >= 0 ; i--)
      {
        for (int j = 0 ; j <= i ;j++)
        {
          digitalWrite(j,1);
          delay(30);

            if (j != i)
            { 
              digitalWrite(j,0);
              delay(30);
            }
        }
              digitalWrite(i,1);
              delay(30);
      }
      for (int x = 0 ; x <= 19; x++)
        {
          digitalWrite(x,0);
          delay(30);
        }
  }
}

void blink2()
{
  for (int z = 1 ;z <= 15 ;z++)
  {
    if (z <= 3)
    {
        for (int i = 0 ; i <= 19 ; i++)
      {
        if (i == 1)
        {
          digitalWrite(1,1);
          digitalWrite(2,1);
        }
        if (i == 8)                digitalWrite(i,1);
        else if (i == 12)          digitalWrite(i,1);
        else if (i == 16)          digitalWrite(i,1);
        delay(400);
        if (z <= 2)        
        {
          digitalWrite(1,0);
          digitalWrite(2,0);
          digitalWrite(8,0);
          digitalWrite(12,0);
          digitalWrite(16,0);
        }     
       
      }
    }
    else if (z <= 6)
    {
        for (int i = 0 ; i <= 19 ; i++)
      {
        if (i == 0)
        {
          digitalWrite(0,1);
          digitalWrite(7,1);
        }
        else if (i == 9)           digitalWrite(i,1);
        else if (i == 13)          digitalWrite(i,1);
        else if (i == 17)          digitalWrite(i,1);
        else {continue;}
        delay(400);
        if (z <= 5)        
        {
          digitalWrite(0,0);
          digitalWrite(7,0);
          digitalWrite(9,0);
          digitalWrite(13,0);
          digitalWrite(17,0);
        }     
      }
    }
    else if (z <= 9)
    {
        for (int i = 0 ; i <= 19 ; i++)
      {
        if (i == 5)
        {
          digitalWrite(5,1);
          digitalWrite(6,1);
        }
        else if (i == 10)           digitalWrite(i,1);
        else if (i == 14)          digitalWrite(i,1);
        else if (i == 18)          digitalWrite(i,1);
        else {continue;}
        delay(400);
        if (z <= 8)        
        {
          digitalWrite(5,0);
          digitalWrite(6,0);
          digitalWrite(10,0);
          digitalWrite(14,0);
          digitalWrite(18,0);
        }   
      }
    }
    else if (z <= 12)
    {
        for (int i = 0 ; i <= 19 ; i++)
      {
        if (i == 3)
        {
          digitalWrite(3,1);
          digitalWrite(4,1);
        }
        else if (i == 11)           digitalWrite(i,1);
        else if (i == 15)          digitalWrite(i,1);
        else if (i == 19)          digitalWrite(i,1);
        else {continue;}
        delay(400);
        if (z <= 11)        
        {
          digitalWrite(3,0);
          digitalWrite(4,0);
          digitalWrite(11,0);
          digitalWrite(15,0);
          digitalWrite(19,0);
        }   
      }
    }
    else if (z <= 15)
    {
      ledOn();
      delay(500);
       for (int j = 1 ; j <= 3 ;j++)
      {
        ledOn();
        delay(200);
        ledOff();
        delay(500);
      }
    }
  }
}

void blink3()
{
for (int z = 1 ; z <= 10 ; z++)
{
  for (int i = 0 ; i <= 19 ; i++)
  {
    if (i == 1)
      {
        digitalWrite(1,1);
        digitalWrite(2,1);
      }
        if (i == 8)                digitalWrite(i,1);
        else if (i == 12)          digitalWrite(i,1);
        else if (i == 16)          digitalWrite(i,1);

             if (i == 5)
        {
          digitalWrite(5,1);
          digitalWrite(6,1);
        }
        else if (i == 10)           digitalWrite(i,1);
        else if (i == 14)          digitalWrite(i,1);
        else if (i == 18)          digitalWrite(i,1);
        else {continue;}
  }
      delay(500);
      ledOff();

  for (int i = 0 ; i <= 19 ; i++)
    {

      if (i == 0)
        {
          digitalWrite(0,1);
          digitalWrite(7,1);
        }
        else if (i == 9)           digitalWrite(i,1);
        else if (i == 13)          digitalWrite(i,1);
        else if (i == 17)          digitalWrite(i,1);

    if (i == 3)
      {
        digitalWrite(3,1);
        digitalWrite(4,1);
      }
        else if (i == 11)           digitalWrite(i,1);
        else if (i == 15)          digitalWrite(i,1);
        else if (i == 19)          digitalWrite(i,1);
        else {continue;}
    }
      delay(500);
      ledOff();
  }
}

void blink4()
{
  for (int z = 1 ; z <= 3;z++)
  {
    for (int r = 1 ; r <= 8 ; r++)
    {
      if (r == 1)
      {
        for (int i = 0 ; i <= 7 ;i++)
        {
        digitalWrite(i,1);
        }
        delay(500);
      }
      if (r == 2)
      {
        for (int i = 8 ; i <= 11 ;i++)
        {
        digitalWrite(i,1);
        }
        delay(500);
      }
      if (r == 3)
      {
        for (int i = 12 ; i <= 15 ;i++)
        {
        digitalWrite(i,1);
        }
        delay(500);
      }
      if (r == 4)
      {
        for (int i = 16 ; i <= 19 ;i++)
        {
        digitalWrite(i,1);
        }
        delay(500);
        ledOff();
      }
      if (r == 5)
      {
        for (int i = 16 ; i <= 19 ;i++)
        {
        digitalWrite(i,1);
        }
        delay(500);
      }
      if (r == 6)
      {
        for (int i = 12 ; i <= 15 ;i++)
        {
        digitalWrite(i,1);
        }
        delay(500);
      }
      if (r == 7)
      {
        for (int i = 8 ; i <= 11 ;i++)
        {
        digitalWrite(i,1);
        }
        delay(500);
      }
      if (r == 8)
      {
        for (int i = 0 ; i <= 7 ;i++)
        {
        digitalWrite(i,1);
        }
        delay(500);
        ledOff();
      }
    }

  }
}

void blink5()
{
  for (int z = 1 ;z <= 12 ;z++)
  {
    for (int r = 1 ; r <= 2; r++)
    {
      if (r == 1)
      {
        for (int i = 0 ; i <= 19 ; i++)
        {
          if (i <= 7 && i >= 0)
          {
            if (i % 2 == 0 )
            {
              digitalWrite(i,1);
            }
          }
          if      (i <= 11 && i >= 8) digitalWrite(i,1);
          else if (i <= 19 && i >= 16) digitalWrite(i,1);
        }
      }
      delay(200);
      ledOff();

      if (r == 2)
      {
        for (int i = 0 ; i <= 19 ; i++)
        {
          if (i <= 7 && i >= 0)
          {
            if (i % 2 == 1 )
            {
              digitalWrite(i,1);
            }
          }
          else if (i <= 15 && i >= 12) digitalWrite(i,1);
        }

      }
      delay(200);
      ledOff();
    }
  }
}  

void blink6()
{
  for (int z = 0 ;z <= 30 ;z++)
  {
  int randomNum = random(19);


  digitalWrite(randomNum,1);
  delay(100);
  digitalWrite(randomNum,0);
  }
}