Blocklab Docs

Electronic Dice

Learn how to create a digital die that rolls a random number when a button is pressed.

Electronic Dice

This project simulates a standard 6-sided die using LEDs and a button. When you press the button, the system picks a random number from 1 to 6 and lights up the corresponding LED to show the result.

What you will learn

  • How to use Variables to store information (the dice number)
  • How to generate Random Integers (random numbers)
  • How to use If / Else If logic to make decisions
  • How to handle Input (Button) and Output (Multiple LEDs)

Import the project

Electronic Dice
Simulates a die roll by choosing a random number and lighting up the matching LED.

How it works

  1. Trigger: The program waits for the button to be pressed.
  2. Randomization: When pressed, a variable named item is set to a random integer between 1 and 6.
  3. Logic: The program checks the value of item using a series of conditions:
    • If item is 1, it turns on LED 2.
    • If item is 2, it turns on LED 3.
    • This pattern continues for all 6 numbers
  4. Reset: After displaying the result, the program waits 2 seconds so you can read the roll, then turns all LEDs OFF to get ready for the next time.

On this page