Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* FastLED and NeoPixelbus for ESP8266
- *
- * By: Andrew Tuline
- *
- * Date: March, 2021
- *
- * Use FastLED for the rich API and NeoPixelBus to drive the LED's on an ESP8266. This is how
- * I believe that WLED drives the LED's on an ESP8266. It uses what is called the NPB's UART mode
- * and is on pin D4 of the ESP8266. You need to use pin D4 here and to change it, you'll need
- * to read up on the NeoPixelBus documentation at:
- *
- * https://github.com/Makuna/NeoPixelBus/wiki/ESP8266-NeoMethods
- *
- * The display routine uses pseudo random numbers to fade in and out a strand of LED's. Feel free
- * to replace it.
- *
- */
- #include <NeoPixelBus.h>
- #include <FastLED.h>
- #define NUM_LEDS 30 // No less than 4.
- const uint8_t PixelPin = D4; // This line is actually ignored and is forced by the method chosen below.
- NeoPixelBus<NeoGrbFeature, NeoEsp8266Uart1800KbpsMethod> strip(NUM_LEDS, PixelPin);
- uint32_t ledData[NUM_LEDS]; // FastLED array, so we can refer to leds[i].
- CRGB *leds = (CRGB*) ledData;
- CRGBPalette16 currentPalette = PartyColors_p; // FastLED palette.
- void setup() {
- Serial.begin(115200);
- delay(1000);
- strip.Begin(); // Reset all the WS2812's to an off state.
- strip.Show();
- } // setup()
- void setPixels(CRGB* leds) { // Display FastLED array onto NeoPixelBus.
- for (int i=0; i<NUM_LEDS; i++) { // We're just copying the array over.
- RgbColor color = RgbColor(leds[i].red, leds[i].green, leds[i].blue);
- strip.SetPixelColor(i, color);
- }
- strip.Show(); // The actual NPB method to show the LED's.
- } // setPixels()
- void loop() {
- twinkleup(); // Throw your own (preferably non-blocking) routine in here.
- setPixels(leds); // This replaces FastLED.show();
- } // loop()
- void twinkleup() {
- uint8_t intensity = 128; // 8-bit percentage of LED's lit.
- random16_set_seed(535); // The randomizer needs to be re-set each time through the loop.
- for (int i=0; i<NUM_LEDS; i++) {
- uint8_t startVal = random8(); // The starting value (aka brightness) for each pixel.
- uint8_t freq = random8(64, 192); // The frequency of our sine wave for each LED. By Andrew Tuline.
- uint8_t pixBri = sin8(startVal + 16 * millis()/(255-freq)); // Combined starting value with speed to come up with unique sine wave for each LED.
- if (random8() > intensity) pixBri = 0; // Reduce number of LED's based on intensity.
- leds[i] = ColorFromPalette(currentPalette, random8()+millis()/100, pixBri, LINEARBLEND); // Use a random colour that slowly changes over time.
- }
- } // twinkleup()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement