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

How it works...

The first code snippet sets the first pixel on the board to the color red using the hex notation for colors. The pixel's interface accepts color values to be given as either a tuple of three integers or as a hex value, which, in Python, correlates to an integer value.

Depending on the type of value given, the library extracts the correct values of the red, green, and blue components of the color and sets the pixel to that color. The second code snippet indicates that when reading back the values, they will always be retrieved as a tuple of the three color components.

The final code snippet demonstrates that the hex notation being used is a standard feature of the Python language, which is used to specify the value of an integer in terms of its hex values. The equivalent integer value can also be used to set a color.