kitesurfer1404 / WS2812FX

WS2812 FX Library for Arduino and ESP8266
MIT License
1.58k stars 344 forks source link

How to use FastLED code as a custom effect? #261

Closed icybladeyt closed 3 years ago

icybladeyt commented 3 years ago

so I'm pretty new to using led strips and I made an animation for a project I'm doing. I also want to use one of the effects you've made. I've been playing around trying to understand this but I feel like I'm stumped and I feel like this is a pretty simple thing to do and that I'm just too stupid to figure it out right now but anyway I just want to know how I can use my animation code as a custom effect so I can then play my animation when the Arduino starts and then your Fire Flicker effect just on a loop.

here's my code for the animation I made with FastLED: https://pastebin.com/QRUCbkTz

and here's the code I've been using to play the Fire Flicker effect: https://pastebin.com/Ya0geFgc

moose4lord commented 3 years ago

If you're just trying to run a FastLED effect as an "intro" and then a WS2812FX effect thereafter, you can put the FastLED effect at the beginning of the setup() function and run the WS2812FX service() function in the loop portion of the sketch. This works with my ESP8266 setup:

#include "WS2812FX.h"
#include "FastLED.h"

#define NUM_LEDS 60
#define DATA_PIN D2

CRGB leds[NUM_LEDS];

WS2812FX ws2812fx = WS2812FX(NUM_LEDS, DATA_PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
  MyAnimation();

  ws2812fx.init();
  ws2812fx.setBrightness(100);
  ws2812fx.setColor(RED);
  ws2812fx.setSpeed(500);
  ws2812fx.setMode(FX_MODE_FIRE_FLICKER);
  ws2812fx.start();
}

void loop() {
  ws2812fx.service();
}

void MyAnimation() {
  leds[0] = CRGB(0, 0, 0);
  leds[1] = CRGB(0, 0, 0);
  ...
}