Microbit
Advanced
60 mins
Teacher/Student led
+125 XP
What you need:
Chromebook/Laptop/PC
Microbit

Microbit Hot Potatoe

Follow this guide to build an exciting game on your Microbit. Start by creating a new project, set up a countdown with animations, and add game-over effects. Download the code and play with friends to see who loses!
Learning Goals Learning Outcomes Teacher Notes Lesson Files

Teacher Class Feed

Load previous activity

    1 - Create a new project

    Go to the https://makecode.microbit.org website and create a new project.

    2 - Create a variable

    In the game there will be a countdown of a random number of seconds. Create a variable called seconds, we will use this to store the amount of seconds.

    Once you've created the variable, add the following code to set the amount of seconds to a number between 4 and 20 when you press the A button.

    input.onButtonPressed(Button.A, function () {
        seconds = randint(4, 20)
    })

    3 - Countdown

    Now add the following new code to subtract 1 from the seconds variable until it is equal to 0.

    let seconds = 0
    input.onButtonPressed(Button.A, function () {
        seconds = randint(4, 20)
        while (seconds > 0) {
            seconds += -1
            basic.pause(1000)
        }
    })

    4 - Animation

    Add the following new code to show an animation while the countdown is on.

    Note that each icon takes 600 milliseconds to display, so each 'second' in the game is actually 2.2 seconds (600 + 600 + 1,000 = 2,200 milliseconds).

    let seconds = 0
    input.onButtonPressed(Button.A, function () {
        seconds = randint(4, 20)
        while (seconds > 0) {
            seconds += -1
            basic.pause(1000)
            basic.showIcon(IconNames.Diamond)
            basic.showIcon(IconNames.SmallDiamond)
        }
    })

    5 - Game over

    Finally add the following new code to show the skull icon and play a sound when the countdown reaches 0.

    let seconds = 0
    input.onButtonPressed(Button.A, function () {
        seconds = randint(4, 20)
        while (seconds > 0) {
            seconds += -1
            basic.pause(1000)
            basic.showIcon(IconNames.Diamond)
            basic.showIcon(IconNames.SmallDiamond)
        }
        basic.showIcon(IconNames.Skull)
        soundExpression.sad.play()
    })

    Unlock the Full Learning Experience

    Get ready to embark on an incredible learning journey! Get access to this lesson and hundreds more in our Digital Skills Curriculum.

    Copyright Notice
    This lesson is copyright of Coding Ireland 2017 - 2025. Unauthorised use, copying or distribution is not allowed.
    πŸͺ Our website uses cookies to make your browsing experience better. By using our website you agree to our use of cookies. Learn more