We'll reuse the same approach taken in the Arduino section for representing the dice roll using patterns of NeoPixels.

Storing the Face Patterns

Here's a simple approach for storing the patterns of the NeoPixels for the dice rolls. We can use a dictionary, which is a storage class in CircuitPython that can store any amount of values which are accessed by using their associated keys. These are called key-value pairs, and a dictionary can hold any number of them. We will use the dice roll number as our key and then a tuple of NeoPixels values associated with the number to represent the dice face patterns.

Like this:

Download: file
dice_pixels = {
 1 : (2,),
 2 : (4, 9),
 3 : (0, 4, 7),
 4 : (1, 3, 6, 8),
 5 : (0, 2, 4, 5, 9),
 6 : (0, 2, 4, 5, 7, 9)
}

You'll see this get used later in the final code.

This guide was first published on Dec 16, 2016. It was last updated on Dec 16, 2016.

This page (Dice Faces) was last updated on Oct 06, 2020.