Rainbow Test
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
|
Color Definitions
We can also use this same process for storing all of the common constants that we duplicate in our examples. For example all the named color defintions can be moved into a serate color-defs.py file like this:
Sample colors.py
1 2 3 4 5 6 7 8 9 10 11 |
|
This sample program imports both the config and the colors file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
|
Note that the string colors.
must appear before each color name. You can shorten
this to be just c.
if you want to keep your code smaller and easier to read.
Hiding Hardware Initialization
We could take this one step further and put the lines that setup the SPI and the Display into a separate function. However, in our labs we want to keep some of this code explicit so we will leave the SPI and Display initialization in our examples.