Skip to content

Instantly share code, notes, and snippets.

@mtnocean
Last active January 4, 2016 07:39
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 mtnocean/8590389 to your computer and use it in GitHub Desktop.
Save mtnocean/8590389 to your computer and use it in GitHub Desktop.
How dimming an LED in software reduces the bit depth
// How dimming in software reduces the bit depth.
// Dimming reduces the brightness level from (0..255) to (0..31)
// eight bits per color to five bits.
// Notice how the LED flickers the second time,
// especially at the lowest brightness levels.
// This is a hardware limitation, not the fault of FastLED.
#include "FastLED.h"
#define NUM_LEDS 1
#define DATA_PIN 13
CRGB leds[NUM_LEDS];
void setup()
{
delay(2000);
//FastLED.addLeds<WS2801, RGB>(leds, NUM_LEDS);
FastLED.addLeds<WS2811, DATA_PIN, GRB>(leds, NUM_LEDS);
}
void loop()
{
// first test
// full brightness
FastLED.setBrightness(255);
// red from 0 to 255 back to 0
for (int i = 0; i < 255; i++)
{
leds [0].red = i;
FastLED.show();
delay (20);
}
for (int i = 255; i > 0; i--)
{
leds [0].red = i;
FastLED.show();
delay (20);
}
delay (1000);
// second test
// one eighth brightness
FastLED.setBrightness(31);
// same code as above
// red from 0 to 255 back to 0
for (int i = 0; i < 255; i++)
{
leds [0].red = i;
FastLED.show();
delay (20);
}
for (int i = 255; i > 0; i--)
{
leds [0].red = i;
FastLED.show();
delay (20);
}
delay (3000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment