Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Poor man's 1D subpixel rendering.
- By: Andrew Tuline
- Date: Oct, 2021
- Supports partial brightness both before and after the 'current' led.
- */
- #include <FastLED.h>
- #define LED_DT 12
- #define NUM_LEDS 60
- struct CRGB leds[NUM_LEDS];
- void setup() {
- Serial.begin(115200);
- LEDS.addLeds<WS2812, LED_DT, GRB>(leds, NUM_LEDS);
- } // setup()
- void loop () {
- float t = (sin((float)millis() / 1000.) + 1.0) / 2.; // Make a slow sine wave and convert output range from -1.0 and 1.0 to between 0 and 1.0.
- t = t * (float)NUM_LEDS; // Now map to the length of the strand.
- for (int i = 0; i < NUM_LEDS; i++)
- {
- float diff = abs(t - (float)i); // Get difference between t and current location. Greater distance = lower brightness.
- if (diff > 2.0) diff = 2.0; // Let's not overflow.
- float bri = 256 - diff * 128; // Scale the brightness to up to 255. Closer = brighter.
- leds[i] = CHSV(0, 255, (uint8_t)bri);
- }
- FastLED.show();
- } // loop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement