Platform: BBC micro:bit (Python)
Objective: Create a digital dice that animates, plays sound (V2), and displays a final random number from 1–6 when shaken.
| Feature | Description |
|---|---|
| Project Name | Animated Dice Simulator |
| Input | Shake gesture detected by the accelerometer |
| Output | LED animation followed by a final dice number (1–6) |
| Sound Output (V2) | Rolling sound during animation and a confirmation tone after the final roll |
| Libraries Used | microbit, random, music |
| Dice Range | 1–6 (inclusive) |
| Animation | Rapid flashing of random numbers on the LED display before the final result |
| Goal | Simulate a realistic dice roll using movement, animation, and sound. |
START
IMPORT microbit, random, music
LOOP forever:
IF device detects shake:
Play rolling sound
REPEAT animation loop 6 times:
Pick a random number 1–6
Display the number briefly
Pause a short time
END REPEAT
Generate final random number 1–6
Display final number
Play confirmation tone
Pause to show result
END LOOP
from microbit import *
import random
import music
while True:
if accelerometer.was_gesture("shake"):
# Play rolling sound (V2 only—safe to run on V1)
music.play(["C4:2", "D4:2", "E4:2", "F4:2"], wait=False)
*********** need more code below ************
# last statment in the program
sleep(1000)
The name of the file will be:
PX_lastname_Dice
PX_lastname_Dice.png — Screenshot inside Python editor showing your code.PX_lastname_Dice.py — Your Python source file.PX_lastname_Dice.txt — Plain-text copy of your code.PX_lastname_Dice.hex — Hex file to run on the physical micro:bit.PX_lastname_Dice.mp4 — Short demo video of the program running on the board.