code.py
 1  # SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
 2  # SPDX-License-Identifier: MIT
 3  """
 4  CircuitPython DotStar rainbow example - multiple DotStars.
 5  
 6  This example is meant for boards that have multiple built-in DotStar LEDs.
 7  
 8  ** Update NUMBER_OF_PIXELS to the match the number of built-in DotStars on the board. It is found
 9  in THREE places in the code.
10  
11  For example:
12  If you are using a FunHouse, change NUMBER_OF_PIXELS to 5.
13  
14  ** DO NOT INCLUDE THE pylint: disable LINE IN THE GUIDE CODE. It is present only to deal with the
15  NUMBER_OF_PIXELS variable being undefined, and the dots setup line being too long with the variable
16  in it in this pseudo-code. As you will be updating the variable in the guide, you will not need
17  the pylint: disable.
18  """
19  # pylint: disable=undefined-variable, line-too-long
20  
21  import time
22  import board
23  from rainbowio import colorwheel
24  import adafruit_dotstar
25  
26  dots = adafruit_dotstar.DotStar(board.DOTSTAR_CLOCK, board.DOTSTAR_DATA, NUMBER_OF_PIXELS, auto_write=False)
27  dots.brightness = 0.3
28  
29  
30  def rainbow(delay):
31      for color_value in range(255):
32          for led in range(NUMBER_OF_PIXELS):
33              pixel_index = (led * 256 // NUMBER_OF_PIXELS) + color_value
34              dots[led] = colorwheel(pixel_index & 255)
35          dots.show()
36          time.sleep(delay)
37  
38  
39  while True:
40      rainbow(0.01)