User Manual
The SPI-or-not decision affects the wiring and strip declaration, but after that everything is the same regardless.
Now, in the setup() function, call begin() to prepare the data and clock pins for DotStar output:
The second line, strip.show() , isn’t absolutely necessary, it’s just there to be thorough. That function pushes data out
to the pixels…since no colors have been set yet, this initializes all the DotStars to an initial “off” state in case some were
left lit by a prior program.
To set the color of an individual DotStar LED, use the setPixelColor() function, which can work a couple of different
ways. Easiest usually involves passing a pixel number and red, green and blue color values:
index is the pixel number, starting at 0 (first pixel), then 1 (second pixel), up to the number of pixels in the strip minus
one. Pixel indices outside this range will simply be ignored.
red , green , blue specify the color, each in a range from 0 (off) to 255 (maximum brightness).
For example, here’s how we’d set the first pixel (index 0) to an orangey color (100% red, 50% green, 0% blue):
An alternate syntax takes just two arguments, a pixel index (same as before) and a single color value as a “packed” 24-
bit integer (often in hexadecimal notation…something advanced programers may be more comfortable working in):
You can “pack” separate red, green and blue values into a single 32-bit type for later use:
Then later you can just pass “magenta” as an argument to setPixelColor() rather than the separate red, green and
blue numbers every time.
setPixelColor() does not have an immediate effect on the LEDs. To “push” the color data to the strip, call show() :
This updates the whole strip at once, and despite the extra step is actually a good thing. If every call to setPixelColor()
had an immediate effect, animation would appear jumpy rather than buttery smooth.
Adafruit_DotStar strip(NUMPIXELS, DOTSTAR_BRG);
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
strip.setPixelColor(index, red, green, blue);
strip.setPixelColor(0, 255, 127, 0);
strip.setPixelColor(index, color);
uint32_t magenta = strip.Color(255, 0, 255);
strip.show();
© Adafruit Industries https://learn.adafruit.com/adafruit-dotstar-leds Page 28 of 48