MYP Design · Year 8 · Lessons so far

micro:bit with MakeCode

Every lesson so far with the micro:bit, in order, followed by nine games to build. Open one to see what you need, the steps, the blocks and something to try next. All of the building happens at makecode.microbit.org.

Lessons

1Hello, MakeCodeYour first program: a name badge that plays when you press a button.

You need

  • micro:bit
  • USB cable
  • A laptop with makecode.microbit.org open

Steps

  1. Open makecode.microbit.org, choose New Project and name it name-badge.
  2. Drag show leds inside on start. Click each LED you want lit to draw your first letter.
  3. Plug in the USB cable and press the purple Download button. If a file lands in Downloads, drag it onto the MICROBIT drive. Your letter appears on the board.
  4. Add one show leds for each letter of your name, with pause (ms) 100 after each. Finish with a blank show leds and pause (ms) 500. That is the gap before the name starts again.
  5. Wrap all of it in repeat 4 times. A repeat block is a loop: it runs the same blocks again and again.
  6. Move everything out of on start and into on button A pressed.
  7. Press Share, then Publish project, and copy the link. Publishing is how you hand work in.

The blocks

MakeCode blocks. Step 2. One letter, shown when the micro:bit starts.
Step 2. One letter, shown when the micro:bit starts.
MakeCode blocks. Step 6. A two-letter name, played four times when you press A.
Step 6. A two-letter name, played four times when you press A.

What happens

Press A and your name plays across the LEDs four times, with a short gap between each run.

The idea. The button is the input, the loop is the process and the LEDs are the output.

Now change it

  • Make on button B pressed do something different.
  • Make the pauses smaller and smaller. Find the fastest speed you can still read.
  • Try show string with your name in it. Work out what it is doing for you.

Documents

2Algorithms 1: making the micro:bit decideEvents, a variable and a condition: show a heart on the fourth press of B.

You need

  • micro:bit
  • USB cable
  • Battery pack

Steps

  1. Show a happy face when you shake the micro:bit: on shake with show icon inside.
  2. Show a sad face when you press A: on button A pressed with show icon inside.
  3. Now the challenge: show a heart when B has been pressed four times. The micro:bit has to remember how many presses there have been, then ask a question about that number.
  4. In the Variables drawer choose Make a Variable and call it B Clicks. A variable is a box with a name on it. In on start, put set B Clicks to 0.
  5. Start a new stack: on button B pressed with change B Clicks by 1 inside. Every press adds one to the box.
  6. Under that, add if … then from the Logic drawer and drop B Clicks = 4 into its gap. This is a condition: a question with only two answers, yes or no.
  7. Inside the if, show the heart, pause, clear the screen and set B Clicks to 0. Setting it back to 0 lets the count start again.

The blocks

MakeCode blocks. Steps 1 and 2. Two events, each with its own answer.
Steps 1 and 2. Two events, each with its own answer.
MakeCode blocks. Steps 4 to 7. The finished counter. MakeCode shows the variable as B_Clicks here; yours reads B Clicks.
Steps 4 to 7. The finished counter. MakeCode shows the variable as B_Clicks here; yours reads B Clicks.

What happens

Three presses of B show nothing. The fourth shows a heart for one second. Four more presses show it again.

The idea. Remembering needs a variable. Checking needs a condition.

Now change it

  • Change the 4 to another number and test it.
  • Show a different icon on the fourth press.
  • Build the Shake Counter: a variable called Shakes that goes up by 1 on every shake, and an icon on the third shake.

Documents

3Choosing your gameThe Mini Project begins: pick one game from the Games Menu.

You need

  • The Games Menu
  • The Criteria A and B sheet

Steps

  1. Read through the Games Menu. It holds 23 micro:bit games in three levels.
  2. Pick two games you like and one you will build. For each, write down one strength and one weakness.
  3. Read the Criteria A and B sheet. It lists the eight pieces of design work you hand in, one for each strand.
  4. Tell Mr. Rawson which game you have chosen.

What happens

You leave with one game chosen and a reason for choosing it.

Documents

4My Game Design: the design packetSummative A and B. Explain your game and exactly how it works, on paper.

You need

  • My Game Design packet
  • The Games Menu
  • A pencil

Steps

  1. Work through the eight parts of the packet in order. Each part is labelled with the strand it earns.
  2. In Part 1, name a real person your game is for.
  3. Write success criteria that you can see or count, such as the score goes up by 1 for each catch.
  4. Plan three versions of one game, each using A, B, A+B and shake in a different way.
  5. Fill in the controls table for your final version. Write not used beside any input your game leaves out.
  6. Draw your four 5 × 5 screens and write out one round of the game step by step.

What happens

A finished packet that another person could build your game from.

The idea. The packet is marked on how clearly it explains your plan.

Documents

5Building your gameTurn the design packet into a working game in MakeCode.

You need

  • Your finished design packet
  • micro:bit
  • USB cable

Steps

  1. Open your packet at the controls table and the block list. They are your plan.
  2. Build one input at a time. Start with button A, download, and test it on the micro:bit.
  3. Add the next input and test again. Small steps keep the game working the whole way through.
  4. Most games keep a score or pick something at random. The two patterns below do those jobs.
  5. Press Share, then Publish project, and post the link in the Google Classroom build thread.

The blocks

MakeCode blocks. Keeping score. A variable goes up by 1 and the micro:bit shows it.
Keeping score. A variable goes up by 1 and the micro:bit shows it.
MakeCode blocks. A random number from 1 to 6 on every shake.
A random number from 1 to 6 on every shake.

What happens

Your game runs on a real micro:bit, and its link is in the build thread.

Now change it

  • Add a sound or an icon for winning.
  • Add a way to start a new game without unplugging the micro:bit.
6Carousel Play DayPlay each other's games and tell the builder what you noticed.

You need

  • micro:bit
  • Your game's sharing link

Steps

  1. Open your own game from its sharing link and download it to your micro:bit.
  2. Move round the room when Mr. Rawson calls. Play each game you reach.
  3. Tell the builder the first thing you did when you picked their game up.
  4. Back at your own game, read what your players noticed and make one change.
  5. If your game changed, publish it again and post the new link.

What happens

Your game has been played by people who did not build it, and you have one idea to borrow from someone else's.

Games to build

Nine games like the ones Year 8 built for the Mini Project. Each one explains how the game works, then gives the basic steps. Build one, then make it your own.

1Magic 8 BallAsk a question, shake, and read your answer.

How the game works

You ask a yes-or-no question out loud and shake the micro:bit. It picks a random number, and each number has its own answer. The player sees the answer scroll past and never sees the number.

You need

  • micro:bit
  • Battery pack

Basic steps

  1. Make a variable called answer.
  2. In on shake, set answer to pick random 0 to 4. That gives five possible numbers: 0, 1, 2, 3 and 4.
  3. Add if … then … else and press its + until it has a branch for each number. Give each branch a condition such as answer = 0.
  4. Put a show string with a different answer in every branch. The last answer goes in the plain else, which catches whatever number is left.
  5. Add show string to on start so the player knows the game is ready.

The blocks

MakeCode blocks. Five numbers, five answers. The else at the bottom catches the number 4.
Five numbers, five answers. The else at the bottom catches the number 4.
MakeCode blocks. A shorter way that some of the class found: keep the answers in a list and let MakeCode pick one.
A shorter way that some of the class found: keep the answers in a list and let MakeCode pick one.

What happens

Each shake scrolls one of the five answers across the screen.

The idea. A random number chooses, and if … else if turns the number into words.

Now change it

  • Write your own answers. Short ones are easiest to read on a 5 × 5 screen.
  • Add a sixth answer: change the random range to 0 to 5 and add one more branch.
  • Show a picture for some answers with show icon.
2Rock, Paper, ScissorsShake to throw a random hand.

How the game works

Two players count to three and shake their micro:bits together. Each micro:bit picks 1, 2 or 3 at random and shows a picture: a small square for rock, a large square for paper, or scissors. The players decide who won.

You need

  • Two micro:bits
  • Two battery packs

Basic steps

  1. Make a variable called hand.
  2. In on shake, set hand to pick random 1 to 3.
  3. Add if … then … else with one extra branch. Test for hand = 1, then hand = 2, and leave the else for 3.
  4. Put a show icon in each branch: small square, square, scissors.

The blocks

MakeCode blocks. Three numbers, three pictures.
Three numbers, three pictures.

What happens

Each shake shows rock, paper or scissors.

The idea. The same shape as the Magic 8 Ball, with pictures in place of words.

Now change it

  • Draw your own rock, paper and scissors with show leds.
  • Play a different note for each hand.
  • Clear the screen after 2 seconds so that the next round starts fresh.
3DiceShake for a number from 1 to 6.

How the game works

The whole game is one event. A shake picks a random number from 1 to 6 and shows it, so the micro:bit can stand in for the dice in any board game.

You need

  • micro:bit
  • Battery pack

Basic steps

  1. Drag out on shake.
  2. Put show number inside it.
  3. Drop pick random 1 to 6 into the number gap.

The blocks

MakeCode blocks. The value block sits inside show number, so no variable is needed.
The value block sits inside show number, so no variable is needed.

What happens

Each shake shows a number from 1 to 6.

The idea. A block that gives a value can go straight into the gap of another block.

Now change it

  • Make a 20-sided dice.
  • Roll two dice: show one number, pause, then show the other.
  • Draw the six dice faces with show leds and show the right face for each number.
4Hot PotatoPass it on before the hidden timer runs out.

How the game works

Press A and pass the micro:bit round the circle. It has secretly chosen a number of seconds between 5 and 15 and is counting down. When the count reaches 0 a skull appears, and whoever is holding it is out.

You need

  • micro:bit
  • Battery pack
  • Three or more players

Basic steps

  1. Make a variable called timer.
  2. In on button A pressed, set timer to pick random 5 to 15 and show an icon that means the game is running.
  3. Add while with the condition timer > 0. A while loop keeps repeating for as long as its condition is true.
  4. Inside the loop put change timer by -1 and pause (ms) 1000. Each trip round the loop takes one second off.
  5. Under the loop, add show icon with the skull.

The blocks

MakeCode blocks. The loop runs once a second until the timer reaches 0.
The loop runs once a second until the timer reaches 0.

What happens

The chessboard icon shows while the potato is hot. After 5 to 15 seconds the skull appears.

The idea. A while loop repeats until something changes, and here the loop itself makes the change.

Now change it

  • Change the range to make rounds longer or shorter.
  • Play a sound when the skull appears.
  • Speed up the last three seconds with a shorter pause.
5ScorekeeperKeep the score for two teams.

How the game works

The micro:bit remembers two numbers, one for each team. Button A adds a point for the home team and button B adds one for the away team. Pressing both together starts a new match.

You need

  • micro:bit
  • Battery pack

Basic steps

  1. Make two variables, home and away. Set both to 0 in on start.
  2. In on button A pressed: change home by 1, then show number with home in the gap.
  3. Build the same for button B with away.
  4. In on button A+B pressed, set both variables to 0 and clear the screen.

The blocks

MakeCode blocks. Two variables, one for each team.
Two variables, one for each team.

What happens

Each press shows that team's new score. A and B together sets both back to 0.

The idea. One variable for each thing the game has to remember.

Now change it

  • Show both scores on shake, one after the other.
  • Show a trophy when a team reaches 5.
  • Add a way to take a point away after a mistake.
6Reaction TimerPress B the moment the dot appears.

How the game works

Press A and the micro:bit counts 3, 2, 1, then waits for a random time and lights one dot. Press B as fast as you can. The micro:bit shows how many milliseconds you took: 1000 milliseconds is one second.

You need

  • micro:bit
  • Battery pack

Basic steps

  1. Make two variables, start and running.
  2. In on button A pressed: show 3, 2, 1, clear the screen, then pause for pick random 1000 to 3000 milliseconds.
  3. Straight after the pause, set start to running time (ms), set running to true and plot x 2 y 2. Running time is the micro:bit's own stopwatch.
  4. In on button B pressed, add if running then. Inside it, set running to false and show running time (ms) minus start.

The blocks

MakeCode blocks. The time now, minus the time the dot appeared, is your reaction time.
The time now, minus the time the dot appeared, is your reaction time.

What happens

A dot appears after a wait of 1 to 3 seconds. Pressing B scrolls your time, usually between 200 and 400.

The idea. running is a true-or-false variable. It lets B work only while a round is on.

Now change it

  • Show a happy face for times under 300.
  • Keep the best time in a variable called best and show it on shake.
  • Light the dot in a random place with pick random 0 to 4 for x and y.
7Catch the DotMove left and right to catch the falling dots.

How the game works

You are a dot on the bottom row, moved left with A and right with B. Another dot appears somewhere on the top row and falls one row at a time. If it lands on you, you score a point.

You need

  • micro:bit
  • Battery pack

Basic steps

  1. Open Advanced, then Game. In on start, set a variable called player to create sprite at x: 2 y: 4. A sprite is a dot the game can move and test.
  2. Button A: player move by -1. Button B: player move by 1.
  3. In forever, set item to a new sprite at a random x from 0 to 4, with y 0, and pause.
  4. Add repeat 4 times holding item change y by 1 and a pause. Four steps take the dot from the top row to the bottom.
  5. After the loop, add if player touching item then with change score by 1 inside, then delete item.

The blocks

MakeCode blocks. Forever makes one dot fall, checks for a catch, deletes the dot and starts again.
Forever makes one dot fall, checks for a catch, deletes the dot and starts again.

What happens

Dots fall one after another, and each catch adds a point.

The idea. The 5 × 5 screen is a grid. x counts across from 0 to 4 and y counts down from 0 to 4.

Now change it

  • Make the dots fall faster by shortening the pause.
  • Take a life for each dot you miss with remove life.
  • Show the score when A and B are pressed together.
8Heads UpHold it to your forehead and guess the word from your friends' clues.

How the game works

Hold the micro:bit upright on your forehead so that only your friends can read it. They give clues and you guess the word. Tip it face down for a correct guess, which scores a point, or face up to pass, which costs a life. Stand it upright again for the next word. A countdown ends the game after 30 seconds.

You need

  • micro:bit
  • Battery pack
  • Two or more players

Basic steps

  1. In on start, set a variable called wordList to an array of words. An array is a list kept in one variable. Then add start countdown (ms) 30000.
  2. In on logo up, set index to a random number from 0 to length of array wordList minus 1. Positions in a list start at 0, so a list of five words has positions 0 to 4.
  3. Still in logo up, show string the word at that position: wordList get value at index.
  4. on screen down: change score by 1. on screen up: remove life 1.

The blocks

MakeCode blocks. Three tilts do three jobs: next word, correct, pass.
Three tilts do three jobs: next word, correct, pass.

What happens

Each time the micro:bit stands upright a word scrolls across. When the 30 seconds are up it shows the score.

The idea. The micro:bit knows which way up it is, so tilting it works like three more buttons.

Now change it

  • Write a word list on one theme, such as animals or films.
  • Change the countdown to 60000 for a one-minute round.
  • Add more words with the + on the array block.
9Twenty-OneDraw cards and get as close to 21 as you dare.

How the game works

Each press of A draws a card worth 1 to 10 and adds it to your total. You choose when to stop. Go over 21 and the game is over. The player who stops closest to 21 wins.

You need

  • micro:bit
  • Battery pack

Basic steps

  1. Make two variables, score and card. Set score to 0 in on start.
  2. In on button A pressed, set card to pick random 1 to 10, then change score by card.
  3. Add if … then … else with the condition score > 21. In then, show GAME OVER and set the score back to 0. In else, show the score.
  4. In on button B pressed, set score to 0 and show 0, ready for the next player.

The blocks

MakeCode blocks. Every card is added to the total, then the total is checked against 21.
Every card is added to the total, then the total is checked against 21.

What happens

The total climbs with each press of A. Above 21 it scrolls GAME OVER and starts again from 0.

The idea. change score by card adds a different amount each time, because the amount is itself a variable.

Now change it

  • Show the card you drew before showing the total.
  • Play a sad sound on GAME OVER.
  • Show a star when the total is exactly 21.
Block pictures are drawn by Microsoft MakeCode. Lessons 1 and 2 are adapted from Intro to Computer Science with MakeCode for micro:bit by Douglas Kiang and Mary Kiang, published by Microsoft MakeCode. The full course is on the Robotics & Control page.