You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
focalintent edited this page Nov 11, 2013
·
1 revision
<wiki:toc max_depth="2" />
How to set an LED's color
There are lots of ways to set an LED's color; this page gives very short examples of several of them.
Set RGB Color
Here are six ways to set an LED's RGB color:
set individual R, G, and B fields, the classic way:
leds[i].r = 255;
leds[i].g = 68;
leds[i].b = 221;
set RGB from a single (hex) color code (v2)
leds[i] = 0xFF44DD;
set RGB from a standard named web/HTML color code (v2)
leds[i] = CRGB::HotPink;
set RGB using 'setRGB' and three values at once (v2)
leds[i].setRGB( 255, 68, 221);
copy RGB color from another led (v2)
leds[i] = leds[j];
use new 'fill_solid', telling it to fill just one led. (v2) Note that this is a pretty silly way to set one pixel, but it lets us illustrate the existence of fill_solid, a new convenience function the library provides.
Six ways to set an LED's color from HSV (Hue, Saturation, Value). In general, they mostly involve assigning a CHSV color to a CRGB color; the colorspace conversion happens through an automatic call to hsv2rgb_rainbow.
It's worth noting that a 'spectrum' and a 'rainbow' are different things; rainbows are more visually color-balanced, and have more yellows and oranges than spectra do. You probably want to start with 'rainbow', and only switch to 'spectrum' if you have a specific need.
Using a 'rainbow' color with hue 0-255, saturating 0-255, and brightness (value) 0-255 (v2)
// Simplest, preferred way: assignment from a CHSV color
leds[i] = CHSV( 224, 187, 255);
// Alternate syntax
leds[i].setHSV( 224, 187, 255);
Setting to a pure, bright, fully-saturated rainbow hue
use new 'fill_solid', telling it to fill just one led. (v2) Note that this is a pretty silly way to set one pixel, but it lets us illustrate the existence of fill_solid, a new convenience function the library provides.
With fill_rainbow. (v2) Note that this is a pretty silly way to set one pixel, but it lets us illustrate the existence of fill_rainbow, a new convenience function the library provides.
A "CRGB" is nothing more than a convenient wrapper for three bytes of raw RGB data: one byte of red, one byte of green, and one byte of blue. You are welcome, and invited, to directly access the underlying memory. These examples show how you read binary RGB data directly from a Serial stream into your array of LED values:
Read a single pixel of RGB data directly into one CRGB (v2).
Serial.readBytes( (char*)(&leds[i]), 3); // read three bytes: r, g, and b.
Read a whole strip's worth of RGB data directly into the leds array at once (v2)