Introduction: Dice Duo Matrix
Welcome to this exciting Arduino project where we'll create an interactive electronic dice using an Nano V3 microcontroller, a pushbutton, and two LED matrix displays. When the button is pressed, the LED matrices will simulate rolling dice by displaying an animation and then show random dice faces. This project is a fun way to dive into programming microcontrollers and working with LED displays.
Supplies
Step 1: Circuit Connection
Nano V3 -> LED Matrix
D12 -> Din
D11 -> CLK
D10 -> CS
5V -> VCC
GND -> GND
The Button is connected to D2 and GND and is pulled LOW when pushed.
The second LED Matrix is daisy-chained.
Step 2: ArduinoCode
You will need to install the “LedControl” library. To do so open the Arduino IDE and go to the Library Manager. Search for “LedControl” (byEberhardFahle) and install.
Step 3: How the Code Works
Library Inclusion and Initialization
● Includes the "LedControl" library to control the LED matrices.
● Initializes a "LedControl" object "lc" with data in ("DIN"), clock ("CLK"), and chip select ("CS") pins connected to pins 12, 11, and 10 of the Arduino, respectively.
● Specifies that there are 2 devices (LED matrices) daisy-chained together.
Defining Dice Face Patterns
● Creates a 2D array "dice" that holds the bitmap patterns for the six faces of a die.
● Each face is an 8-byte array representing an 8x8 LED matrix pattern.
Button Setup
● Sets up the pushbutton connected to digital pin 2.
● Initializes variables for button state and debounce functionality to handle mechanical switch bouncing
Setup Function
● Wakes up both LED matrices from shutdown mode.
● Sets the brightness to a medium level.
● Clears any previous display on the matrices.
● Seeds the random number generator for generating random dice values.
● Configures the button pin with an internal pull-up resistor.
● Reads the initial state of the button.
Displaying Dice Faces
● A helper function that takes a dice face pattern and displays it on the specified LED matrix.
Animation Function
● Creates a rolling dice animation by displaying random patterns on the LED matrices for one second.
● Enhances the user experience by simulating the rolling effect before showing the final result.
Main Loop
● Continuously checks the state of the button and debounces it.
● When a button press is detected:
○ Calls the "animate()" function to display the rolling animation.
○ Generates two random numbers between 1 and 6 for the dice values.
○ Displays the corresponding dice face on each LED matrix using the "displayDieFace()" function
Step 4: Main Loop
● Continuously checks the state of the button and debounces it.
● When a button press is detected:
○ Calls the "animate()" function to display the rolling animation.
○ Generates two random numbers between 1 and 6 for the dice values.
○ Displays the corresponding dice face on each LED matrix using the "displayDieFace()" function





