![Adafruit Feather M4 Express Manual Download Page 131](http://html1.mh-extra.com/html/adafruit/feather-m4-express/feather-m4-express_manual_2845857131.webp)
By default,
auto_write=True
, meaning any changes you make to your pixels will be sent automatically. Since
True
is
the default, if you use that setting, you don't need to include it in your LED object at all. We've chosen to
set
auto_write=False
. If you set
auto_write=False
, you must include
pixels.show()
each time you'd like to send data
to your pixels. This makes your code more complicated, but it can make your LED animations faster!
NeoPixel Helpers
Next we've included a few helper functions to create the super fun visual effects found in this code. First is
wheel()
which we just learned with the
Internal RGB LED
(https://adafru.it/Bel)
. Then we have
color_chase()
which requires you
to provide a
color
and the amount of time in seconds you'd like between each step of the chase. Next we have
rainbow_cycle()
, which requires you to provide the mount of time in seconds you'd like the animation to take. Last,
we've included a list of variables for our colors. This makes it much easier if to reuse the colors anywhere in the code,
as well as add more colors for use in multiple places. Assigning and using RGB colors is explained in
this section of the
CircuitPython Internal RGB LED page
(https://adafru.it/Bel)
.
Main Loop
Thanks to our helpers, our main loop is quite simple. We include the code to set every NeoPixel we're using to red,
green and blue for 1 second each. Then we call
color_chase()
, one time for each
color
on our list with
0.1
second
delay between setting each subsequent LED the same color during the chase. Last we call
rainbow_cycle(0)
, which
means the animation is as fast as it can be. Increase both of those numbers to slow down each animation!
Note that the longer your strip of LEDs, the longer it will take for the animations to complete.
NeoPixel RGBW
NeoPixels are available in RGB, meaning there are three LEDs inside, red, green and blue. They're also available in
RGBW, which includes four LEDs, red, green, blue and white. The code for RGBW NeoPixels is a little bit different than
RGB.
If you run RGB code on RGBW NeoPixels, approximately 3/4 of the LEDs will light up and the LEDs will be the incorrect
color even though they may appear to be changing.
This is because NeoPixels require a piece of information for each
available color (red, green, blue and possibly white).
Therefore, RGB LEDs require three pieces of information and RGBW LEDs require FOUR pieces of information to work.
So when you create the LED object for RGBW LEDs, you'll include
bpp=4
, which sets bits-per-pixel to four (the four
pieces of information!).
Then, you must include an extra number in every color tuple you create. For example, red will be
(255, 0, 0, 0)
. This is
how you send the fourth piece of information. Check out the example below to see how our NeoPixel code looks for
using with RGBW LEDs!
We have a ton more information on general purpose NeoPixel know-how at our NeoPixel UberGuide
https://learn.adafruit.com/adafruit-neopixel-uberguide
# CircuitPython demo - NeoPixel RGBW
import time
import board
import neopixel
pixel_pin = board.A1
© Adafruit Industries
https://learn.adafruit.com/adafruit-feather-m4-express-atsamd51
Page 136 of 183