Module 4: Intermediate micro:bit Projects
Description
Simulating Probability With a Micro:bit
In this activity, you will be using Makecode. Go to http://makecode.microbit.org/ and delete the “on start” and “forever” blocks.
From the Input drawer, click and drag the “on shake” block to the workspace. We will use “on shake” to simulate the coin toss. Take a moment to click on the down arrow to see the variety of inputs.
Click and drag an “if true then else” block from the Logic drawer and snap it into place within the “on shake” block.
From the Math drawer click and drag a “pick random true or false” block into place over
to create a condition. The “pick random true or false” gives a random true or false answer which we will assign to heads or tails.
Notice how the “true” is high-lighted in yellow as the new block, “pick random true or false” , is dragged into its space!
Now we want to show heads or tails. From the Basic drawer select the “show icon” block and chose an icon to represent head and tails. You may wish to create your own image using the “show leds” block. In the image below, the happy face represents heads and the sad face, tails.
We want to make sure that the image is changing on each shake so add “pause” and “clear screen” blocks from the Basic drawer. The pause is measured in milliseconds (ms).
On simulated micro:bit (upper left corer), click on 'Shake' to check your code.
Extensions:
Remix this code to create a simulator of a six- sided number cube or Rock-Paper-Scissors.
Hint: You will need to create a variable for either the “roll” or the “shake”.
Then think about how many rolls or shakes you need for each probability simulation.
Task
Challenge: Can you think of another way to add some wait time?
Challenge: Can you remix the code to count the number of heads and tails?
Challenge: What’s the experimental probability of flipping a head out of 10 tries, 20?
Link to completed Coin Toss.
Extension
Complete the code remix challenge above and save your project.
Before moving onto the next module you will need to complete the next assignment which is to share links to two completed MakeCode projects. We suggested completing one of the challenges above (remix project to count number of heads or tails) or create one of the extension activities (dice roll or rock, paper, scissors).
Learning Objectives
In this module you learned how to:
- Code the Micro:bit to simulate flipping a coin
- Remix the existing code to represent a six-sided number cube
Continue to Module 5: Classroom Implementation »
Latest 10 Submissions
-
Adrienne Britten : 334.3 days ago
-
Carlo Melaragno : 1477.9 days ago
-
Jonathon Butler : 1527.7 days ago
-
Becky Wynne : 1529.9 days ago
-
Jenny Templeton : 1530.8 days ago
-
Tanya Michaud : 1531.9 days ago
-
Danica Donald : 1533.9 days ago
-
Andrew Forgrave : 1538.4 days ago
-
Emily Sturgeon : 1539 days ago
-
Bailey : 1739.7 days ago