Dotstar Helpers - Adafruit Feather M4 Express Manual

Table of Contents

Advertisement

to your pixels. This makes your code more complicated, but it can make your LED animations faster!

DotStar Helpers

We've included a few helper functions to create the super fun visual effects found in this code.
First is
which we just learned with the
wheel()
requires you to provide a
, and
slice_rainbow()
rainbow_cycle()
each step of the animation.
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
of the CircuitPython Internal RGB LED page
The two slice helpers utilise a nifty feature of the DotStar library that allows us to use math to light up LEDs in repeating
patterns.
slice_alternating()
back and forth.
slice_rainbow()
use our handy color variables. This slice code only works when the total number of LEDs is divisible by the slice size, in
our case 2 and 6. DotStars come in strips of 30, 60, 72, and 144, all of which are divisible by 2 and 6. In the event that
you cut them into different sized strips, the code in this example may not work without modification. However, as long
as you provide a total number of LEDs that is divisible by the slices, the code will work.
Main Loop
Our main loop begins by calling
can change this number to change how fast each color is displayed. Next, we call
there's a 0.1 second delay between each change in the animation. Then, we fill the strip white to create a clean
backdrop for the rainbow to display. Then, we call
call
, which means it's as fast as it can possibly be. Increase or decrease either of these numbers to
rainbow_cycle(0)
speed up or slow down the animations!
Note that the longer your strip of LEDs is, the longer it will take for the animations to complete.
We have a ton more information on general purpose DotStar know-how at our DotStar UberGuide
https://learn.adafruit.com/adafruit-dotstar-leds
Is it SPI?
We explained at the beginning of this section that the LEDs respond faster if you're using hardware SPI. On some of
the boards, there are HW SPI pins directly available in the form of MOSI and SCK. However, hardware SPI is available
on more than just those pins. But, how can you figure out which? Easy! We wrote a handy script.
We chose pins A1 and A2 for our example code. To see if these are hardware SPI on the board you're using, copy and
paste the code into code.py using your favorite editor, and save the file. Then connect to the serial console to see the
results.
To check if other pin combinations have hardware SPI, change the pin names on the line reading:
is_hardware_SPI(board.A1, board.A2):
simple!
© Adafruit Industries
Internal RGB LED
and the length of time you'd like it to be displayed. Next, are
color
which require you to provide the amount of time in seconds you'd between
(https://adafru.it/Bel).
first lights up the even number LEDs and then the odd number LEDs and repeats this
lights up every sixth LED with one of the six rainbow colors until the strip is filled. Both
once for each
color_fill()
to the pins you want to use. Then, check the results in the serial console. Super
https://learn.adafruit.com/adafruit-feather-m4-express-atsamd51
(https://adafru.it/Bel). Then we have
on our list and sets each to hold for
color
, for a 0.1 second delay in the animation. Last we
slice_rainbow(0.1)
color_fill()
slice_alternating()
seconds. You
0.5
, which means
slice_alternating(0.1)
if
Page 143 of 183
which
,
this section

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the Feather M4 Express and is the answer not in the manual?

Related Products for Adafruit Feather M4 Express

Table of Contents

Save PDF