Now you add the green and blue LEDs to the mix. But what happens when you step up from monochrome to RGB color? Imagine that you’ve gone through the whole gamma experiment above with just the red channel of a WS2812 LED. Gamma correction can make your single-color LED effects look a lot better. Here’s a quick and dirty Python script that will generate the lookup table for you. In the end, I usually implement the gamma correction as a lookup table that turns the desired brightness directly into whatever numbers the chip’s PWM routine wants, so there’s no math left to do at all at runtime. Taking the 2.314’th root of a given number is a tall task to ask of a microcontroller, though, and it’s probably overkill. Get it just right, and you get a smooth transition from dark to light across the full range. If the gamma is set lower than your eye’s gamma, differences will be muted, and it will look muddy. If we gamma-correct with a value that’s bigger than your eye’s natural gamma an image will look too contrasty - there will be jumps in the brightness where you’d want it to be smooth. I like to think of choosing a gamma in terms of black-and-white photography. 2.2 is a standard value for CRT monitors in the PC world, and 1.8 used to be the standard for Macs.īut if you really care about the way your LEDs look, you’ll want to tweak the gamma to your particular conditions. Arbitrarily picking gamma to be 2 makes that fractional gamma exponent into a more comfortable square root and usually isn’t too far wrong. For your intuition, gamma values from just around 1.5 to around 3 are probably reasonable to consider. That exponential relationship, requiring more and more additional light to create a perceptible difference in brightness, is characterized by that Greek exponent: gamma. We perceive brightness using some kind of power law: if B is perceived brightness and L is the luminance - the amount of physical light that’s getting through your irises - the relationship looks roughly something like this: It’s not the LED or the PWM controlling it that’s to blame, however. On a WS2812, with its eight-bit-per-color resolution, stepping from a red value of 5 to a red value of 10 more than doubles the apparent brightness, while stepping from 250 to 255 can barely be noticed at all. If you ramp up the duty cycle from 0% to 100%, it looks like the LED gets brighter very quickly in the beginning and then somewhere around the 50% mark stops getting brighter at all. If you’ve ever dimmed a single LED using pulse-width modulation (PWM) before, you have certainly noticed that the response is non-linear. If you’re ready to take your RGB blinkies to the next level, read on! In the end, I’ll provide pointers to getting the last 5% right if you really want to geek out. In this shorty, I’ll work through just enough to get things 95% right: making yellows, magentas, and cyans about as bright as reds, greens, and blues. Surprisingly, there’s been new science done on color perception in the last twenty years, even though both eyes and colors have been around approximately forever. It turns out that even getting a color-fade “right” is very tricky. You might already know this from the one-LED case, but are you doing it right when you combine red, green, and blue? Any LED responds (almost) linearly to pulse-width modulation (PWM), putting out twice as much light when it’s on for twice as long, but the human eye is dramatically nonlinear. If you just want to make some shinies, and you don’t care about any sort of accurate color reproduction or consistent brightness, you’re all set.īut if you want to display video, encode data in colors, or just make some pretty art, you might want to think a little bit harder about those RGB values that you’re pushing down the wires. You would think that there’s nothing to know about RGB LEDs: just buy a (strip of) WS2812s with integrated 24-bit RGB drivers and start shuffling in your data.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |