-
-
Save nathanmelenbrink/b50f6d85eab65c0cf80cd5216d417f9c to your computer and use it in GitHub Desktop.
FastLED_RGBW for low dimming values
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
/* | |
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