-
-
Save jasoncoon/d54216fc8ce2eb0ecee87f8002d421c5 to your computer and use it in GitHub Desktop.
#include "FastLED.h" | |
// How many leds in your strip? | |
#define NUM_LEDS 60 | |
// For led chips like Neopixels, which have a data line, ground, and power, you just | |
// need to define DATA_PIN. For led chipsets that are SPI based (four wires - data, clock, | |
// ground, and power), like the LPD8806 define both DATA_PIN and CLOCK_PIN | |
#define DATA_PIN 3 | |
#define CLOCK_PIN 13 | |
// Define the array of leds | |
CRGB leds[NUM_LEDS]; | |
void setup() { | |
// Uncomment/edit one of the following lines for your leds arrangement. | |
// FastLED.addLeds<TM1803, DATA_PIN, RGB>(leds, NUM_LEDS); | |
// FastLED.addLeds<TM1804, DATA_PIN, RGB>(leds, NUM_LEDS); | |
// FastLED.addLeds<TM1809, DATA_PIN, RGB>(leds, NUM_LEDS); | |
// FastLED.addLeds<WS2811, DATA_PIN, RGB>(leds, NUM_LEDS); | |
// FastLED.addLeds<WS2812, DATA_PIN, RGB>(leds, NUM_LEDS); | |
// FastLED.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS); | |
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS); | |
// FastLED.addLeds<APA104, DATA_PIN, RGB>(leds, NUM_LEDS); | |
// FastLED.addLeds<UCS1903, DATA_PIN, RGB>(leds, NUM_LEDS); | |
// FastLED.addLeds<UCS1903B, DATA_PIN, RGB>(leds, NUM_LEDS); | |
// FastLED.addLeds<GW6205, DATA_PIN, RGB>(leds, NUM_LEDS); | |
// FastLED.addLeds<GW6205_400, DATA_PIN, RGB>(leds, NUM_LEDS); | |
// FastLED.addLeds<WS2801, RGB>(leds, NUM_LEDS); | |
// FastLED.addLeds<SM16716, RGB>(leds, NUM_LEDS); | |
// FastLED.addLeds<LPD8806, RGB>(leds, NUM_LEDS); | |
// FastLED.addLeds<P9813, RGB>(leds, NUM_LEDS); | |
// FastLED.addLeds<APA102, RGB>(leds, NUM_LEDS); | |
// FastLED.addLeds<DOTSTAR, RGB>(leds, NUM_LEDS); | |
// FastLED.addLeds<WS2801, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS); | |
// FastLED.addLeds<SM16716, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS); | |
// FastLED.addLeds<LPD8806, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS); | |
// FastLED.addLeds<P9813, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS); | |
// FastLED.addLeds<APA102, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS); | |
// FastLED.addLeds<DOTSTAR, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS); | |
} | |
void loop() { | |
sunrise(); | |
FastLED.show(); | |
} | |
void sunrise() { | |
// total sunrise length, in minutes | |
static const uint8_t sunriseLength = 30; | |
// how often (in seconds) should the heat color increase? | |
// for the default of 30 minutes, this should be about every 7 seconds | |
// 7 seconds x 256 gradient steps = 1,792 seconds = ~30 minutes | |
static const uint8_t interval = (sunriseLength * 60) / 256; | |
// current gradient palette color index | |
static uint8_t heatIndex = 0; // start out at 0 | |
// HeatColors_p is a gradient palette built in to FastLED | |
// that fades from black to red, orange, yellow, white | |
// feel free to use another palette or define your own custom one | |
CRGB color = ColorFromPalette(HeatColors_p, heatIndex); | |
// fill the entire strip with the current color | |
fill_solid(leds, NUM_LEDS, color); | |
// slowly increase the heat | |
EVERY_N_SECONDS(interval) { | |
// stop incrementing at 255, we don't want to overflow back to 0 | |
if(heatIndex < 255) { | |
heatIndex++; | |
} | |
} | |
} |
You will need to rest the heatIndex back to zero. Even if you reset the register for heatIndex sill has the value of 255.
Before setup add heatIndex = 0;
And to rest at the end, in void sunrise()
EVERY_N_SECONDS(interval) {
// stop incrementing at 255, we don't want to overflow back to 0
if (heatIndex < 255) {
heatIndex++;
}
if (heatIndex == 255) {
heatIndex = 0;
}
how do you turn the leds on?
You turn them on with FastLED.show();
Hi
I'm looking to set up a sunrise effect in FastLED via ESPHome.
Can I (and how would I) use this script somehow within ESPHome?
Kr
PS: can ColorFromPaletteExtended()
(FastLED/FastLED#202) be integrated in this?
COuld be a dumb question but how do i speed this up? i have changed sunrise length but i just see white
Setting the duration too low will cause interval
to be 0 hence why immediately white. I suggest to just temporarily hardcode the interval to 1 if you want to speed it up. The full runtime will be about 4 min 16 secs
it works fine on on my alexa controlled esp8266 but when the cycle is done and i switch it of by software and on again, the cycle does not start from the beginning. it just turns on with full white. How can i have a reset at the end of the sunrise cycle (+x minutes.)?