Datasheet
Then, in the setup() function, call begin() to prepare the data pin for NeoPixel 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 NeoPixels to an initial “off” state in case some were
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 a couple different 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 an RGBW strip), with no light from red/green/blue,
use:
An alternate syntax has just two arguments:
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
The Adafruit Trinket 5V 16 MHz board requires a little extra setup. You can see the steps required in the
“strandtest” example sketch.
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);
© Adafruit Industries https://learn.adafruit.com/adafruit-neopixel-uberguide Page 72 of 100