Last active
November 12, 2021 19:19
-
-
Save jildertviet/e64f53bd075231d8c20e090bc22b174a to your computer and use it in GitHub Desktop.
Simple FastLED example to fade a WS2816B LED by using two virtual WS2812Bs / NeoPixels
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> | |
// Not tested with more then one LED! | |
#define NUM_LEDS 2 | |
#define DATA_PIN D4 | |
CRGB leds[NUM_LEDS]; | |
void setup() { | |
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS); // GRB ordering is assumed | |
} | |
void loop() { | |
for(int i=0; i<65535; i+=32){ | |
float v = i / 65535.0; // map to 0 - 1 | |
v = sin(v * 3.1415 * 2) * 0.5 + 0.5; // Sine wave from 0.0 - 1.0 | |
uint16_t val = v * 65535; // map to range of uint16_t | |
char split[2]; | |
memcpy(split, &val, 2); | |
leds[0] = CRGB(split[0], split[1], split[1]); | |
leds[1] = CRGB(split[1],split[0],split[0]); | |
FastLED.show(); | |
delay(1); // Crashes without delay() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment