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

How it works...

A global variable called RGB is created; this is a dictionary that is used for matching color names to their RGB color codes. This allows the color values to be retrieved by their names, instead of directly specifying their hex codes every time they need to be used. The first snippet uses the RGB code to set the first pixel to the color red.

The second block of code loops through each color name in alphabetical order and sets a pixel to that color. Since there are eight colors defined in the color lookup dictionary, the first eight pixels will have their colors set—each pixel will have its own color from the list of colors.