Datasheet
left lit by a prior program.
In the strandtest example, loop() doesn’t set any pixel colors on its own — it calls other functions that create animated
effects. So let’s ignore it for now and look ahead, inside the individual functions, to see how the strip is controlled.
There are two ways to set the color of a pixel. The first is:
or, if you're using RGBW strips:
The first argument — n in this example — is the pixel number along the strip, starting from 0 closest to the Arduino. If
you have a strip of 30 pixels, they’re numbered 0 through 29. It’s a computer thing. You’ll see various places in the
code using a for loop, passing the loop counter variable as the pixel number to this function, to set the values of
multiple pixels.
The next three arguments are the pixel color, expressed as red, green and blue brightness levels, where 0 is dimmest
(off) and 255 is maximum brightness. The last
optional
argument is for white, which will only be used if the strip was
defined during creation as an RGBW type and the strip actually is RGBW type.
To set the 12th pixel (#11, counting from 0) to magenta (red + blue), you could write:
to set the 8th pixel (#7 counting from 0) to half-brightness white, with no light from red/green/blue, use:
An alternate syntax has just two arguments:
Here, color is a 32-bit type that merges the red, green and blue values into a single number. This is sometimes easier
or faster for some (but not all) programs to work with; you’ll see the strandtest code uses both syntaxes in different
places.
You can also convert 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.
strip.setPixelColor(n, red, green, blue);
strip.setPixelColor(n, red, green, blue, white);
strip.setPixelColor(11, 255, 0, 255);
strip.setPixelColor(7, 0, 0, 0, 127);
strip.setPixelColor(n, color);
uint32_t magenta = strip.Color(255, 0, 255);
© Adafruit Industries https://learn.adafruit.com/adafruit-neopixel-uberguide Page 44 of 68