code.py
 1  # SPDX-FileCopyrightText: 2021 Brent Rubell for Adafruit Industries
 2  #
 3  # SPDX-License-Identifier: MIT
 4  
 5  """
 6  'neopixel_builtin.py'.
 7  
 8  =================================================
 9  playing with the metro express builtin NeoPixel
10  """
11  
12  import time
13  import board
14  import neopixel
15  
16  # we only have one neopixel on our metro express
17  NEO = neopixel.NeoPixel(board.NEOPIXEL, 1)
18  NEO.brightness = 0.5
19  
20  # primary colors
21  RED = (255, 0, 0)
22  GREEN = (0, 255, 0)
23  BLUE = (0, 0, 255)
24  
25  COLORS = [RED, GREEN, BLUE]
26  
27  for i in COLORS:
28      NEO[0] = i
29      NEO.show()
30      time.sleep(0.3)
31  
32  # shows all colors by trying all combinations of RGB levels
33  for red_level in range(0, 256, 100):
34      for green_level in range(0, 256, 100):
35          for blue_level in range(0, 256, 100):
36              print("red: ", red_level, "green: ", green_level, "blue: ", blue_level)
37              NEO[0] = (red_level, green_level, blue_level)
38              NEO.show()
39              # wait 0.2 seconds to give us time to see the colors
40              time.sleep(1)
41  NEO[0] = (0, 0, 0)
42  NEO.show()