Project 003: LED Dice


  • To design and program an electrical LED dice using a microcontroller and 7 LEDs

Design and write the program in the embedded system that generates a random number between 1 and 6 (inclusive) when a push button is pressed, and displays the corresponding number of dots on the 7 LEDs for 2 seconds. You can use a pseudo-random number generator and a switch-case statement to map the numbers to the LEDs. For example, 1 can be shown as the center dot, 2 as the opposite dots, 3 as a diagonal line, 4 as a square, 5 as a cross, and 6 as a hexagon. You may also add other features like sound, animation, or delay to enhance the user experience.

Required Components List

  • Microcontroller board (such as PSoC board, TI TIVA board, or similar)
  • Breadboard and jumper wires
  • 7 LEDs (2 yellows, 2 green LEDs, 2 blue LEDs, and one red LED)
  • 11 220-ohm resistors
  • An L293 TTL Chip (Datasheet)

R330ohm 220 Ω (red red brn gld / red red blk blk brn) × 11
LED Green 64 Red LED × 1
LED Green 64 Green LED × 2
LED Green 64 Blue LED × 2
LED Green 64 Yellow LED × 2
IC 16pin DipChip s L293D Quadruple Half-H Drivers × 1

LedDice 01

Circuit Diagram

  • Insert the 7 LEDs on the breadboard to form a dice diagram, as shown above. Connect each LED to a 220-ohm resistor. The resistors limit the current flowing through the LEDs and protect them from damage due to overcurrent.
  • Connect each LED-resistor pair to an output pin of the L293D chip as shown in the diagram.
  • Connect pins LEDR, LEDG, LEDB, and LEDY to the microcontroller. Ensure that these pins are set to output mode in the program.

Conn LedDice 3v3

Safety Tips:

  • Do not connect the LEDs directly to the digital pins without resistors.
  • Disconnect the power cable (including the USB on the microcontroller board) before making any changes to the circuit.

Pin configurations

DevicePort.Pin Signal TypeModuleDirectionDrive Mode


  1. Start a new project in your IDE and create a folder named "003_LED_Dice".
  2. Include the necessary header files.
  3. Define the pins for 4 pairs of LEDs and a push button. Make sure that the pins for the LEDs are set to output mode, and the pin for the button is set to input mode with a pull-up or pull-down resistor.
  4. Generate a random dice value and display it on the LEDs.
  5. If the push button (SW1) is pressed, continue to display a new dice value every 200ms.
  6. If the button is released, continue to display a dice value for 1 second, then stop.
  7. Check if the button is pressed again, and repeat steps 5 to 6 accordingly.

Programming Tips:

  • To detect the state of SW1, consider using software edge detection methods that trigger an action when the button's state changes from pressed to released or vice versa. For example::
    • When SW1 is pressed, start displaying new dice values every 200 ms.
    • When SW1 is released, continue to display new dice values every 200ms for 1 second, then stop.

© 2024 Air Supply Information Center (Air Supply BBS)