Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Dancing Shadows for FastLED
- By: Steve Pomeroy @xxv
- Link: https://github.com/Aircoookie/WLED/blob/447b811fa07629673ab009b48e8157d3e110070a/wled00/FX.cpp#L3759
- Converted from WLED to FastLED by: Andrew Tuline
- Link: https://pastebin.com/TeqMpJ5L
- Date: Valentines Day 2022
- Dancing shadows has two controls, intensity and speed. Feel free to play with them.
- Originally (as far as I know) written for WLED on an ESP8266 and ESP32, this was ported on
- a Nano, so it should work on lots of devices.
- */
- #include <FastLED.h>
- #define LED_DT 12
- #define NUM_LEDS 60
- uint8_t max_bright = 128;
- struct CRGB leds[NUM_LEDS];
- CRGBPalette16 currentPalette = PartyColors_p;
- CRGBPalette16 targetPalette;
- typedef struct Spotlight {
- float speed;
- uint8_t colorIdx;
- int16_t position;
- unsigned long lastUpdateTime;
- uint8_t width;
- uint8_t type;
- } spotlight;
- #define SPOT_TYPE_SOLID 0
- #define SPOT_TYPE_GRADIENT 1
- #define SPOT_TYPE_2X_GRADIENT 2
- #define SPOT_TYPE_2X_DOT 3
- #define SPOT_TYPE_3X_DOT 4
- #define SPOT_TYPE_4X_DOT 5
- #define SPOT_TYPES_COUNT 6
- #ifdef AVR
- #define SPOT_MAX_COUNT 16 // Number of simultaneous waves.
- #else
- #define SPOT_MAX_COUNT 32
- #endif
- uint8_t intensity = 128; // An adjustable control.
- uint8_t speedv = 128; // Another adjustable control.
- bool initialize = true;
- spotlight spotlights[SPOT_MAX_COUNT];
- void setup() {
- Serial.begin(115200);
- LEDS.addLeds<WS2812, LED_DT, GRB>(leds, NUM_LEDS);
- FastLED.setBrightness(max_bright);
- Serial.println(SPOT_MAX_COUNT);
- } // setup()
- void loop () {
- dancing_shadows();
- FastLED.show();
- } // loop()
- void dancing_shadows(void) {
- uint8_t numSpotlights = map(intensity, 0, 255, 2, SPOT_MAX_COUNT);
- fadeToBlackBy(leds, NUM_LEDS, 64);
- unsigned long time = millis();
- bool respawn = false;
- for (uint8_t i = 0; i < numSpotlights; i++) {
- if (!initialize) { // advance the position of the spotlight
- int16_t delta = (float)(time - spotlights[i].lastUpdateTime) *
- (spotlights[i].speed * ((1.0 + speedv) / 100.0));
- if (abs(delta) >= 1) {
- spotlights[i].position += delta;
- spotlights[i].lastUpdateTime = time;
- }
- respawn = (spotlights[i].speed > 0.0 && spotlights[i].position > (NUM_LEDS + 2))
- || (spotlights[i].speed < 0.0 && spotlights[i].position < -(spotlights[i].width + 2));
- }
- if (initialize || respawn) {
- spotlights[i].colorIdx = random8();
- spotlights[i].width = random8(1, 10);
- spotlights[i].speed = 1.0 / random8(4, 50);
- if (initialize) {
- spotlights[i].position = random16(NUM_LEDS);
- spotlights[i].speed *= random8(2) ? 1.0 : -1.0;
- } else {
- if (random8(2)) {
- spotlights[i].position = NUM_LEDS + spotlights[i].width;
- spotlights[i].speed *= -1.0;
- } else {
- spotlights[i].position = -spotlights[i].width;
- }
- }
- spotlights[i].lastUpdateTime = time;
- spotlights[i].type = random8(SPOT_TYPES_COUNT);
- }
- CRGB color = ColorFromPalette(currentPalette, spotlights[i].colorIdx, 255, LINEARBLEND);
- int start = spotlights[i].position;
- if (spotlights[i].width <= 1) {
- if (start >= 0 && start < NUM_LEDS) {
- leds[start] = blend(leds[start], color, 128);
- }
- } else {
- switch (spotlights[i].type) {
- case SPOT_TYPE_SOLID:
- for (uint8_t j = 0; j < spotlights[i].width; j++) {
- if ((start + j) >= 0 && (start + j) < NUM_LEDS) {
- leds[start + j] = blend(leds[start + j], color, 128);
- }
- }
- break;
- case SPOT_TYPE_GRADIENT:
- for (uint8_t j = 0; j < spotlights[i].width; j++) {
- if ((start + j) >= 0 && (start + j) < NUM_LEDS) {
- leds[start + j] = blend(leds[start + j], color, cubicwave8(map(j, 0, spotlights[i].width - 1, 0, 255)));
- }
- }
- break;
- case SPOT_TYPE_2X_GRADIENT:
- for (uint8_t j = 0; j < spotlights[i].width; j++) {
- if ((start + j) >= 0 && (start + j) < NUM_LEDS) {
- leds[start + j] = blend(leds[start + j] , color, cubicwave8(2 * map(j, 0, spotlights[i].width - 1, 0, 255)));
- }
- }
- break;
- case SPOT_TYPE_2X_DOT:
- for (uint8_t j = 0; j < spotlights[i].width; j += 2) {
- if ((start + j) >= 0 && (start + j) < NUM_LEDS) {
- leds[start + j] = blend(leds[start + j], color , 128);
- }
- }
- break;
- case SPOT_TYPE_3X_DOT:
- for (uint8_t j = 0; j < spotlights[i].width; j += 3) {
- if ((start + j) >= 0 && (start + j) < NUM_LEDS) {
- leds[start + j] = blend(leds[start + j], color, 128);
- }
- }
- break;
- case SPOT_TYPE_4X_DOT:
- for (uint8_t j = 0; j < spotlights[i].width; j += 4) {
- if ((start + j) >= 0 && (start + j) < NUM_LEDS) {
- leds[start + j] = blend(leds[start + j], color, 128);
- }
- }
- break;
- }
- }
- }
- if (initialize) initialize = false;
- } // dancing_shadows()
Add Comment
Please, Sign In to add comment