Infinity Mirror


// Use if you want to force the software SPI subsystem to be used for some reason (generally, you don't)
// #define FASTLED_FORCE_SOFTWARE_SPI
// Use if you want to force non-accelerated pin access (hint: you really don't, it breaks lots of things)
// #define FASTLED_FORCE_SOFTWARE_SPI
// #define FASTLED_FORCE_SOFTWARE_PINS
#include "FastLED.h"

///////////////////////////////////////////////////////////////////////////////////////////
//
// Move a white dot along the strip of leds.  This program simply shows how to configure the leds,
// and then how to turn a single pixel white and then off, moving down the line of pixels.
// 

//colors aren't accurate
CRGB _realRed=CRGB::Blue;
CRGB _realGreen=CRGB::Red;
CRGB _realBlue=CRGB::Green;
CRGB _realYellow=0xFF00FF;
CRGB _realWhite=0xFFFFFF;
CRGB _realBlack=0x000000;

const int MODE_POT=A0;

// How many leds are in the strip?
#define NUM_LEDS 10

// Data pin that led data will be written out over
#define DATA_PIN 3

// This is an array of leds.  One item for each led in your strip.
CRGB leds[NUM_LEDS];

int _colorIndex=0;
CRGB _curColor=CRGB::Black;
int _direction=1;

// This function sets up the ledsand tells the controller about them
void setup() {
  // sanity check delay - allows reprogramming if accidently blowing power w/leds
    delay(2000);

    // Uncomment one of the following lines for your leds arrangement.
    FastLED.addLeds(leds, NUM_LEDS);

    pinMode(MODE_POT,INPUT);

    Serial.begin(9600);
}

// This function runs over and over, and is where you do the magic to light
// your leds.
void loop() {
int potval=analogRead(MODE_POT);
  Serial.println(potval);
  
  int index=0;
  if (potval>680)
    Mode_1();
  else if (potval>630)
    Mode_2(); //blue
  else if (potval>590)
    Mode_3(); //red
  else if (potval>490)
    Mode_4(); //green
  else if (potval>364)
    Mode_5(); //yellow
  else if (potval>265)
    Mode_6(); //white
  else
    Mode_7();
}

//Mode 1 is cycling between blue, green, red and white, one led segment at a time.
void Mode_1() {
  CRGB backGround=_curColor;
  backGround.nscale8(55);
  
  if (_direction==1)
  {
   // Move a single white led 
   for(int whiteLed = 0; whiteLed < NUM_LEDS; whiteLed = whiteLed + 1) {
      // Turn our current led on to white, then show the leds
      leds[whiteLed] = _curColor;

      // Show the leds (only one of which is set to white, from above)
      FastLED.show();

      // Wait a little bit
      delay(100);

      // Turn our current led back to black for the next loop around
      leds[whiteLed] = backGround;
   }
  }
  else
  {
   // Move a single white led 
   for(int whiteLed = NUM_LEDS; whiteLed >-1; whiteLed = whiteLed - 1) {
      // Turn our current led on to white, then show the leds
      leds[whiteLed] = _curColor;

      // Show the leds (only one of which is set to white, from above)
      FastLED.show();

      // Wait a little bit
      delay(100);

      // Turn our current led back to black for the next loop around
      leds[whiteLed] = backGround;
   }
  }
  
   _colorIndex++;
   if (_colorIndex>3)
      _colorIndex=0;

   switch(_colorIndex)
   {
      case 0:
        _curColor=_realGreen;
        break;

      case 1:
        _curColor=_realRed;
        break;
        
      case 2:
        _curColor=_realBlue;
        break;
        
      case 3:
        _curColor=_realYellow;
        break;      
   }

   _direction=_direction*-1;  
}

//Mode 2 is solid blue, all the time.
void Mode_2() {
   // Move a single white led 
   for(int whiteLed = 0; whiteLed < NUM_LEDS; whiteLed = whiteLed + 1) {
      // Turn our current led on to white, then show the leds
      leds[whiteLed] = _realBlue;

      // Show the leds (only one of which is set to white, from above)
      FastLED.show();

      // Wait a little bit
      delay(100);
   }
}

//Mode 3 is solid red, all the time.
void Mode_3() {
   // Move a single white led 
   for(int whiteLed = 0; whiteLed < NUM_LEDS; whiteLed = whiteLed + 1) {
      // Turn our current led on to white, then show the leds
      leds[whiteLed] = _realRed;

      // Show the leds (only one of which is set to white, from above)
      FastLED.show();

      // Wait a little bit
      delay(100);
   }
}

//Mode 4 is solid green, all the time.
void Mode_4() {
   // Move a single white led 
   for(int whiteLed = 0; whiteLed < NUM_LEDS; whiteLed = whiteLed + 1) {
      // Turn our current led on to white, then show the leds
      leds[whiteLed] = _realGreen;

      // Show the leds (only one of which is set to white, from above)
      FastLED.show();

      // Wait a little bit
      delay(100);
   }
}

//Mode 5 is solid yellow, all the time.
void Mode_5() {
   // Move a single white led 
   for(int whiteLed = 0; whiteLed < NUM_LEDS; whiteLed = whiteLed + 1) {
      // Turn our current led on to white, then show the leds
      leds[whiteLed] = _realYellow;

      // Show the leds (only one of which is set to white, from above)
      FastLED.show();

      // Wait a little bit
      delay(100);
   }
}

//Mode 6 is solid white, all the time.
void Mode_6() {
   // Move a single white led 
   for(int whiteLed = 0; whiteLed < NUM_LEDS; whiteLed = whiteLed + 1) {
      // Turn our current led on to white, then show the leds
      leds[whiteLed] = _realWhite;

      // Show the leds (only one of which is set to white, from above)
      FastLED.show();

      // Wait a little bit
      delay(100);
   }
}


//Mode 7 is a single led, rotating from red to blue to green to yellow to white
void Mode_7() {
 CRGB backGround=_realBlack;
  
  if (_direction==1)
  {
   // Move a single white led 
   for(int whiteLed = 0; whiteLed < NUM_LEDS; whiteLed = whiteLed + 1) {
      // Turn our current led on to white, then show the leds
      leds[whiteLed] = _curColor;

      // Show the leds (only one of which is set to white, from above)
      FastLED.show();

      // Wait a little bit
      delay(200);

      // Turn our current led back to black for the next loop around
      leds[whiteLed] = backGround;
   }
  }
  else
  {
   // Move a single white led 
   for(int whiteLed = NUM_LEDS; whiteLed >-1; whiteLed = whiteLed - 1) {
      // Turn our current led on to white, then show the leds
      leds[whiteLed] = _curColor;

      // Show the leds (only one of which is set to white, from above)
      FastLED.show();

      // Wait a little bit
      delay(200);

      // Turn our current led back to black for the next loop around
      leds[whiteLed] = backGround;
   }
  }
  
   _colorIndex++;
   if (_colorIndex>3)
      _colorIndex=0;

   switch(_colorIndex)
   {
      case 0:
        _curColor=_realGreen;
        break;

      case 1:
        _curColor=_realRed;
        break;
        
      case 2:
        _curColor=_realBlue;
        break;
        
      case 3:
        _curColor=_realYellow;
        break;      
   }

   _direction=_direction*-1;  
}