Adafruit ESP32-S3 Manual page 140

Tft feather
Table of Contents

Advertisement

those. The
library is separate, which is why you needed to install it before
neopixel
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
object, provide it the NeoPixel LED pin
neopixel.NeoPixel()
using the
module, and tell it the number of LEDs. You save this object to the
board
variable
.
pixel
Then, you set the NeoPixel brightness using the
attribute.
brightness
brightness
expects float between
and
. A float is essentially a number with a decimal in it.
0
1.0
The brightness value represents a percentage of maximum brightness;
is 0% and
0
is 100%. Therefore, setting
sets the brightness to
1.0
pixel.brightness = 0.3
30%. The default brightness, which is to say the brightness if you don't explicitly set it,
is
. The default is really bright! That is why there is an option available to easily
1.0
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
. Note that the RGB
(255, 0, 0)
value includes the parentheses. The
attribute expects the full RGB value
fill()
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 of red, 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
, which has the maximum level of red, and
(255, 0, 0)
no green or blue. Green would be
, etc. For the colors between, you
(0, 255, 0)
©Adafruit Industries
Page 140 of 263

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the ESP32-S3 and is the answer not in the manual?

Subscribe to Our Youtube Channel

Table of Contents

Save PDF