Mathematics Game Microbit
Intermediate
60 mins
Teacher/Student led
145 points
What you need:
Chromebook/Laptop/PC
Microbit

Exactly 11

In this step-by-step lesson, you'll create a new Microbit project and develop a game where you guess when 11 seconds have passed. You'll learn to create and set variables, calculate time differences, and display results. Coding skills will be honed through practical application.
Learning Goals Learning Outcomes Teacher Notes Lesson Files

Live Class Feed

This is a live feed of the latest activity by your students on this lesson. It will update in real-time as they work on the lesson.
Load previous activity

    1 - Create a new Microbit project

    Create a new Microbit project.

    2 - Create a 'starttime' variable

    In the game the player will try and guess when 11 seconds has passed. We will need a variable to remember the start time to create a variable called 'starttime'.

    3 - Set the start time

    Now add the following code to remember when the clock is started and to show an icon to let the user know the clock has started.

    let starttime = 0
    input.onButtonPressed(Button.A, function () {
        starttime = input.runningTime()
    basic.showIcon(IconNames.SmallDiamond)
    })
    
    


    The running time (ms) block returns the number of milliseconds since the program started. (One second is 1000 milliseconds).


    4 - Create a 'taken' variable

    Now create a variable called 'taken', we are going to use this to store the amount of time it has taken between pressing A and pressing B.

    5 - Set the taken time

    Now let's program the B button to set the 'taken' by subtracting the 'starttime' from the current running time.

    Add the following code.

    input.onButtonPressed(Button.B, function () {
        taken = input.runningTime() - starttime
    })
    
    

    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. 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