Program a Microbit to be a dice and show a number between 1 and 6.
Go to the makecode.microbit.org website and create a new project.
Go to the Makecode.com Microbit website using the link below and click on the 'New Project' button underneath the 'My Projects' heading.
Install the micro:bit app on your iPad or tablet.
Open the app, tap 'Create code' and then create a new project.
We are going to program the Microbit to show a number between 1 and 6 when you shake it.
First let's detect a shake, add the following code to your project.
input.onGesture(Gesture.Shake, function () { })
Next let's show the number 0 when you shake it.
Add the show number 0 inside the on [shake] block.
input.onGesture(Gesture.Shake, function () { basic.showNumber(0) })
Now let's show a random number between 1 and 6, just like a dice.
Put a pick random 1 to 6 inside the show number 0 block.
input.onGesture(Gesture.Shake, function () { basic.showNumber(randint(1, 6)) })
That's it you've completed the project! If you do have a Microbit you can send your code to it and use it as a dice.
Give your project a name and send it to your Microbit by following these steps: