The next block of code lets you define favorite colors, which the NeoPixel will call upon later (see image).
There are 2 ways to set the color of any pixel. The first is:
strip.setPixelColor(n, red, green, blue);
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 3 arguments are the pixel color, expressed as numerical brightness levels for red, green, and blue, where 0 is dimmest (off) and 255 is maximum brightness.
An alternate syntax has just 2 arguments:
strip.setPixelColor(n, color);
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 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:
uint32_t magenta = strip.Color(255, 0, 255);
Then later you can just pass magenta as an argument to setPixelColor rather than the separate red, green, and blue numbers each time.
The overall brightness of all the LEDs can be adjusted using setBrightness(). This takes a single argument, a number in the range 0 (off) to 255 (max brightness). For example, to set a strip to ¼ brightness, use:
strip.setBrightness(64);
NOTE: setPixelColor() does not have an immediate effect on the LEDs. To
“push” the color data to the strip, call show():
strip.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.