Created
December 10, 2017 12:16
-
-
Save stevelord/82c4ee236209e36d0a70f33bc331994a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <FastLED.h> | |
#define LED_PIN 1 | |
#define NUM_LEDS 50 | |
#define BRIGHTNESS 255 | |
#define LED_TYPE WS2811 | |
#define COLOR_ORDER GRB | |
CRGB leds[NUM_LEDS]; | |
CRGBPalette16 currentPalette; | |
TBlendType currentBlending; | |
void setup() { | |
delay( 3000 ); // power-up safety delay | |
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip ); | |
FastLED.setBrightness( BRIGHTNESS ); | |
currentPalette = RainbowColors_p; | |
currentBlending = LINEARBLEND; | |
} | |
void loop() | |
{ | |
ChangePaletteFromLight(); | |
static uint8_t startIndex = 0; | |
startIndex = startIndex + 1; /* motion speed */ | |
FillLEDsFromPaletteColors( startIndex); | |
FastLED.show(); | |
delay(100);// / UPDATES_PER_SECOND); | |
} | |
void FillLEDsFromPaletteColors( uint8_t colorIndex) | |
{ | |
uint8_t brightness = 16; | |
for( int i = 0; i < NUM_LEDS; i++) { | |
leds[i] = ColorFromPalette( currentPalette, colorIndex, brightness, currentBlending); | |
colorIndex += 3; | |
} | |
} | |
// We're going to use built-in palettes, but you can define your own (look at the ColorPalette | |
// tutorial for inspiration). To add more options, just copy the 2nd if statement and change | |
// the numbers and palettes. Presets worth trying include: | |
// RainbowStripeColors_p, LavaColors_p, ForestColors_p and PartyColors_p. | |
void ChangePaletteFromLight() | |
{ | |
int ldrStatus = 0; | |
ldrStatus = analogRead(A1); | |
if (ldrStatus < 200){ currentPalette = RainbowColors_p; currentBlending = LINEARBLEND; } // Use original blinkenlight palette in the dark. | |
if (ldrStatus > 199 && ldrStatus < 400){ currentPalette = OceanColors_p; currentBlending = LINEARBLEND; } // Blue | |
if (ldrStatus > 399){ currentPalette = CloudColors_p; currentBlending = LINEARBLEND; } // Blue | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment