Snippets

Jason Matusiak Flood Lights

Created by Jason Matusiak
#include <FastLED.h>

#define LED_PIN     6
#define NUM_LEDS    5
#define BRIGHTNESS  255
#define LED_TYPE    WS2811
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];
CRGB colorIndex[5];

int inPin0 = 3;   // input0
int inPin1 = 4;   // input1
int inPin2 = 5;   // input2
int val = 0;     // variable to store the read value
int numColors = 0;
int k = 0;
  
void setup() {
  pinMode(inPin0, INPUT_PULLUP);      // sets the digital pin 3 as input
  pinMode(inPin1, INPUT_PULLUP);      // sets the digital pin 4 as input
  pinMode(inPin2, INPUT_PULLUP);      // sets the digital pin 5 as input
  DDRD = B11000001;  // sets Arduino pins to output and input
  val = (PIND >> 3) & 0x7;
  
  delay( 3000 ); // power-up safety delay
  FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
  FastLED.setBrightness(  BRIGHTNESS );
  
  //currentBlending = NOBLEND;

  if(val == 0)
  {
    //test sequence
    numColors = 3;
    colorIndex[0] = CRGB::Red;
    colorIndex[1] = CRGB::Green; 
    colorIndex[2] = CRGB::Blue; 
  }
  else if (val == 1)
  {
    //Halloween
    numColors = 2;
    colorIndex[0] = CRGB::Orange;
    colorIndex[1] = CRGB::Purple; 
  }
  else if (val == 2)
  {
    //Autumn
    numColors = 5;
    colorIndex[0] = CRGB::Red;
    colorIndex[1] = CRGB::Yellow; 
    colorIndex[2] = CRGB::Green;
    colorIndex[3] = CRGB::Orange;
    colorIndex[4] = CRGB::Purple; 
  }
  else if (val == 3)
  {
    //Christmas
    numColors = 2;
    colorIndex[0] = CRGB::Red;
    colorIndex[1] = CRGB::Green; 
  }
  else if (val == 4)
  {
    //Patriotic
    numColors = 3;
    colorIndex[0] = CRGB::Blue;
    colorIndex[1] = CRGB::Gray; 
    colorIndex[2] = CRGB::Red;
  }
  else if (val == 5)
  {
    //Easter
    numColors = 4;
    colorIndex[0] = CRGB::Pink;
    colorIndex[1] = CRGB::Gray; 
    colorIndex[2] = CRGB::Purple;
    colorIndex[3] = CRGB::Yellow;
  }
}


void loop()
{
  if(val == 0)
  {
    for(int k = 0; k < numColors; k++)
    {
      for(int i = 0; i < NUM_LEDS; i++) 
      { 
        leds[i] = colorIndex[(i+k)%numColors];
      }
      FastLED.show();
      FastLED.delay(3000);
    }
  }
  else
  {
      for(int j = 0; j <256; j++)
      {
          for(int i = 0; i < NUM_LEDS; i++) 
          { 
            leds[i] = blend( CRGB::Black, colorIndex[(i+k)%numColors], j);
            FastLED.show();
            FastLED.delay(1);
          }
      }
      
      FastLED.delay(300000);
      for(int j = 255; j >=0; j--)
      {
          for(int i = 0; i < NUM_LEDS; i++) 
          { 
            leds[i] = blend( CRGB::Black, colorIndex[(i+k)%numColors], j);
            FastLED.show();
            FastLED.delay(1);
          }
      }
      //FastLED.delay(300000);
      k++;
      if (k == numColors)
      {
        k = 0;
      }
  }
}

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.