those. The neopixel library is separate, which is why you needed to install it before
getting started.
Next, you set up the NeoPixel LED. To interact with hardware in CircuitPython, your
code must let the board know where to look for the hardware and what to do with it.
So, you create a neopixel.NeoPixel() object, provide it the NeoPixel LED pin
using the board module, and tell it the number of LEDs. You save this object to the
variable pixel .
Then, you set the NeoPixel brightness using the brightness attribute. brightness
expects float between 0 and 1.0 . A float is essentially a number with a decimal in it.
The brightness value represents a percentage of maximum brightness; 0 is 0% and
1.0 is 100%. Therefore, setting pixel.brightness = 0.3 sets the brightness to
30%. The default brightness, which is to say the brightness if you don't explicitly set it,
is 1.0 . The default is really bright! That is why there is an option available to easily
change the brightness.
Inside the loop, you turn the NeoPixel red for 0.5 seconds, green for 0.5 seconds, and
blue for 0.5 seconds.
To turn the NeoPixel red, you "fill" it with an RGB value. Check out the section below
for details on RGB colors. The RGB value for red is (255, 0, 0) . Note that the RGB
value includes the parentheses. The fill() attribute expects the full RGB value
including those parentheses. That is why there are two pairs of parentheses in the
code.
You can change the RGB values to change the colors that the NeoPixel cycles
through. Check out the list below for some examples. You can make any color of the
rainbow with the right RGB value combination!
That's all there is to changing the color and setting the brightness of the built-in
NeoPixel LED!
RGB LED Colors
RGB LED colors are set using a combination ofred, green, and blue, in the form of an
(R,G, B) tuple. Each member of the tuple is set to a number between 0 and 255 that
determines the amount of each color present. Red, green and blue in different
combinations can create all the colors in the rainbow! So, for example, to set an LED
to red, the tuple would be (255, 0, 0) , which has the maximum level of red, and
no green or blue. Green would be (0, 255, 0) , etc. For the colors between, you
©Adafruit Industries Page 140 of 263