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
- Trigger: The program waits for the button to be pressed.
- Randomization: When pressed, a variable named
itemis set to a random integer between 1 and 6. - Logic: The program checks the value of
itemusing a series of conditions:- If
itemis 1, it turns on LED 2. - If
itemis 2, it turns on LED 3. - This pattern continues for all 6 numbers
- If
- 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.