User Manual
In the DotStar library,
hue
is expressed as a 16-bit
number. Starting from 0 for red, this increments first
toward yellow (around 65536/6, or 10922 give or take a
bit), and on through green, cyan (at the halfway point of
32768), blue, magenta and back to red. In your own
code, you can allow any hue-related variables to
overflow
or
underflow
and they’ll “wrap around” and do
the correct and expected thing, it’s really nice.
Saturation
determines the intensity or purity of the
color…this is an 8-bit number ranging from 0 (no
saturation, just grayscale) to 255 (maximum saturation,
pure hue). In the middle, you’ll start to get sort of pastel
tones.
Value
determines the brightness of a color…it’s also an
8-bit number ranging from 0 (black, regardless of hue or
saturation) to 255 (maximum brightness).
setPixelColor() and fill() both still want RGB values though, so we convert to these from HSV by using the ColorHSV()
function:
If you just want a “pure color” (fully saturated and full brightness), the latter two arguments can be left off:
In either case, the resulting RGB value can then be passed to a pixel-setting function, e.g.:
There is
no
corresponding function to go the other way, from RGB to HSV. This is on purpose and by design, because
conversion in that direction is often ambiguous — there may be multiple valid possibilities for a given input. If you look
at some of the example sketches you’ll see they
keep track of their own hues
…they
don’t
assign colors to pixels and
then try to read them back out again.
…and Gamma Correction
Something you might observe when working with more nuanced color changes is that things may appear overly bright
or washed-out. It’s generally not a problem with simple primary and secondary colors, but becomes more an issue with
blends, transitions, and the sorts of pastel colors you might get from the ColorHSV() function.
Numerically
the color
values are correct, but
perceptually
our eyes make something different of it, as explained in this
guide (https://adafru.it/w2B).
The gamma32() function takes a packed RGB value (as you might get out of Color() or ColorHSV()) and filters the result
to look more perceptually correct.
uint32_t rgbcolor = strip.ColorHSV(hue, saturation, value);
uint32_t rgbcolor = strip.ColorHSV(hue);
strip.fill(rgbcolor);
© Adafruit Industries https://learn.adafruit.com/adafruit-dotstar-leds Page 30 of 48