Skip to content

Instantly share code, notes, and snippets.

@nathanmelenbrink
Last active December 25, 2022 20:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathanmelenbrink/b50f6d85eab65c0cf80cd5216d417f9c to your computer and use it in GitHub Desktop.
Save nathanmelenbrink/b50f6d85eab65c0cf80cd5216d417f9c to your computer and use it in GitHub Desktop.
FastLED_RGBW for low dimming values
/*
FastLED_RGBW attempt for low dimming values
* Original code by Jim Bumgardner (http://krazydad.com).
* Modified by David Madison (http://partsnotincluded.com).
https://github.com/FastLED/FastLED/wiki/FastLED-Temporal-Dithering
https://www.reddit.com/r/FastLED/comments/dp43fg/dim_led_below_1256_levels/
*/
#include "FastLED.h"
#include "FastLED_RGBW.h"
// number of LEDs on the strip
#define NUMPIXELS 240
const int bPin = A4;
const int DATA_PIN = 21;
int b;
CRGBW leds[NUMPIXELS];
CRGB *ledsRGB = (CRGB *) &leds[0];
void setup() {
FastLED.addLeds<WS2812B, DATA_PIN, RGB>(ledsRGB, getRGBWsize(NUMPIXELS));
}
void loop() {
// read from the sensor:
b = map(analogRead(bPin), 0, 4095, 0, 255);
for (int i = 0; i < NUMPIXELS; i++) {
leds[i] = CRGBW(0, 0, b, 0);
}
// I also dim the whole strip by the same value
// to achieve dithering less than 1/256 brightness
FastLED.setBrightness(b);
FastLED.show();
FastLED.delay(1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment