Game Microbit
Beginner
60 mins
Teacher/Student led
115 points
What you need:
Chromebook/Laptop/PC
Microbit

Reaction Timer

In this step-by-step lesson, you'll create a 'Reaction Timer' project on the Micro:bit website. You'll learn to code a welcome message, a countdown, and a random delay. You'll also create variables to store time stamps and record player reactions. This lesson will enhance your coding skills and understanding of variables.
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 Project

    First, go to the Micro:bit website. Click on 'New Project' and name your project as 'Reaction Timer'.

    2 - Creating a Welcome Message

    Let's start by creating a welcome message that will be displayed when you power on your Microbit.

    Add the following code to your project:

    basic.showString("Get Ready")

    3 - Creating a Countdown

    After the welcome message, we are going to create a countdown from 3 to 1 and then show a line on the screen.

    Add the following new code to your project:

    basic.showString("Get Ready")
    basic.showNumber(3)
    basic.pause(1000)
    basic.showNumber(2)
    basic.pause(1000)
    basic.showNumber(1)
    basic.pause(1000)
    basic.showLeds(`
        . . . . .
        . . . . .
        # # # # #
        . . . . .
        . . . . .
        `)
    You could also create a function called 'countdown' and pass in the amount of seconds you want to count down. Have a think about how you could do this.

    4 - Adding a Random Delay

    To make the game unpredictable, let's add a random delay after the countdown. 

    Add the following new code to create a random delay between 1 to 5 seconds (1,000 to 5,000 milliseconds) and then show the signal (a fully lit up LED screen) to the player.

    basic.showString("Get Ready")
    basic.showNumber(3)
    basic.pause(1000)
    basic.showNumber(2)
    basic.pause(1000)
    basic.showNumber(1)
    basic.pause(1000)
    basic.showLeds(`
        . . . . .
        . . . . .
        # # # # #
        . . . . .
        . . . . .
        `)
    basic.pause(Math.randomRange(1000, 5000))
    basic.showLeds(`
        # # # # #
        # # # # #
        # # # # #
        # # # # #
        # # # # #
        `)
    

    5 - Create Variables

    We will need 2 variables to store some time stamps:

    1. startTime - to store when the signal is shown to the player.
    2. reactionTime - to store when the player presses the A button.

    Create these variables now and then add the following new code to set the startTime variable.

    let startTime = 0
    basic.showString("Get Ready")
    basic.showNumber(3)
    basic.pause(1000)
    basic.showNumber(2)
    basic.pause(1000)
    basic.showNumber(1)
    basic.pause(1000)
    basic.showLeds(`
        . . . . .
        . . . . .
        # # # # #
        . . . . .
        . . . . .
        `)
    basic.pause(randint(1000, 5000))
    basic.showLeds(`
        # # # # #
        # # # # #
        # # # # #
        # # # # #
        # # # # #
        `)
    startTime = input.runningTime()
    
    The running time (ms) block stores the number of milliseconds since the program started.

    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