element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
microbit
  • Learn
  • Learning Center
  • STEM Academy
  • microbit
  • More
  • Cancel
microbit
micro:bit Blog 10 BBC micro:bit Projects in 10 Days: Day Seven - Roll the Dice
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join microbit to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: jlucas
  • Date Created: 3 Jun 2016 11:44 AM Date Created
  • Views 4588 views
  • Likes 20 likes
  • Comments 9 comments
  • micro:bit
  • bbc micro:bit
  • microbit
  • beginner micro:bit projects
  • bbc microbit
  • ten bbc micro:bit projects
  • beginner_microbit_projects
  • bbc_micro:bit
  • 10projects10days
Related
Recommended

10 BBC micro:bit Projects in 10 Days: Day Seven - Roll the Dice

jlucas
jlucas
3 Jun 2016

About this project

 

This project turns the BBC micro:bit into an electronic dice, programming the device to display a random number from 1-6 on the LED array when shaken.

 

What you'll need

 

1 x BBC micro:bit

1 x Micro USB

1 x Computer or tablet

2 x AAA Batteries & Battery Holder

 

Project walkthrough

 

  • Go to the BBC micro:bit website, click 'create code' and begin a new Microsoft Block Editor project.

 

  • From the Input commands menu, drag in an 'if [shake] do' tile.

 

  • When the device is shaken, we want it to display a random number from 1-6. To do this, first we need to create a new variable.

 

  • Attach a 'set [item]' tile, and rename the variable to 'roll'.

 

  • Now go to the Math command menu and attach a 'pick random [0] to [4]' tile. Change the figure in the dialog box to 5, like so:

 

image

  • Because the roll has a range of 0-5 rather than 1-6, we have to tell the device to show the number one when it rolls a zero, the number two when it rolls a one, and so on.

 

  • Drag in an 'if/do' tile and, for 'if', attach a '[0] = [0]' tile from the logic menu. Drag a 'roll' variable into the left dialogue box.

 

  • For 'do', attach a 'show leds' tile and set it to display the 'one' side of a standard dice by lighting up a single bulb at the co-ordinate 2/2.

 

image

 

  • Click on the blue cog symbol in your 'if/do' tile and add an 'else if/do' option.

 

  • Use this to program your BBC micro:bit to display the 'two' side of the dice when the device rolls a one.

 

image

 

  • Using more 'else/if' and 'else' tiles, repeat the steps above so that when the roll is 2, 3, 4 5, the device shows a 3, 4, 5 and 6 dice side respectively.

image

image

  • You're done! Run your program to test it in the right-hand emulator, then click compile to download the script and transfer it to your BBC micro:bit.

 

When your students have mastered this project, what else can they do with the random command? Challenge them to develop different projects using the LED array, such as a dice that displays images rather than numbers, or a 'trick dice' that only rolls even numbers. Let us know what they come up with in the comments section below...

  • Sign in to reply

Top Comments

  • volly
    volly over 8 years ago in reply to vandia +3
    vandia https://www.youtube.com/watch?v=WK8jhupl7r0
  • volly
    volly over 8 years ago in reply to vandia +3
    vandia Shake Dice in Action: https://www.youtube.com/watch?v=1-Rdz9tb2bg
  • balearicdynamics
    balearicdynamics over 9 years ago +2
    Something that seems not yet noted ... The value added of this example is just Dice ... It sounds to me as random that is not a so obvious but useful feature in micro-controller small devices Enrico
Parents
  • vandia
    vandia over 8 years ago

    Would love to see a photo of the actual outcome on a working unit!

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
Comment
  • vandia
    vandia over 8 years ago

    Would love to see a photo of the actual outcome on a working unit!

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
Children
  • volly
    volly over 8 years ago in reply to vandia

    vandia

     

    https://www.youtube.com/watch?v=WK8jhupl7r0

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • vandia
    vandia over 8 years ago in reply to volly

    Thanks.... good to see an actual unit working lol.
    My computer lagged during the video, but it didn't show the dice thing, did it? I was curious about a die-rolling animation on it lol.

     

    Also, what do you call a platform like that, with LEDs in a square, if I wanted to connect and control it with another device? I need one a good few inches wide, lol. Any ideas?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • volly
    volly over 8 years ago in reply to vandia

    vandia

     

    Shake Dice in Action:

     

    https://www.youtube.com/watch?v=1-Rdz9tb2bg

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • vandia
    vandia over 8 years ago in reply to volly

    Thanks! ...if I get one, I may want to do a shaking animation on the screen when you're shaking it!
    Or, anyone else is free to give it a try! lol

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube