MicroPython Cookbook
上QQ阅读APP看书,第一时间看更新

How to do it...

To do this, perform the following steps:

  1. Run the following lines of code in the REPL:
>>> from adafruit_circuitplayground.express import cpx
>>> RGB = dict(black=0x000000, blue=0x0000FF, green=0x00FF00, 
... cyan=0x00FFFF, ... red=0xFF0000, magenta=0xFF00FF, yellow=0xFFFF00,
... white=0xFFFFFF) >>> cpx.pixels[0] = RGB['red']
  1. You should see the first NeoPixel turn red.
  2. Use the following code to set the first eight pixels to one of the named colors in alphabetical order:
>>> for i, name in enumerate(sorted(RGB)):
...     cpx.pixels[i] = RGB[name]