← Teacher guide

Time between

Students store the running time at one moment and take it away from a later reading, to measure how long something took.

micro:bit: talk and play · Time · about 40 minutes · Open the student lesson

Classroom resources

Load these into Waypoints Prepare: choose Load URL and paste the copied address, or download the file and import it. In Prepare, the worksheet's Teacher edition shows the answers; the student copy hides them.

Students will be able to

Timing

Predict and Run 8 min · Investigate 10 min · Modify 8 min · Mix it up 3 min · Make 8 min · Egg timer 3 min

Before class

running time (Input › more) is the number of milliseconds since the micro:bit switched on. It never restarts at a press, so on its own it is a big number. Timing is a subtraction: store running time in a variable at the start (start), then later show running time − start. 1000 ms is one second; dividing by 1000 gives seconds with a decimal. In the simulator, timings are a little longer than on a real micro:bit.

Running the lesson

  1. Predict: some students choose 7500, the running time itself. Ask what start holds.
  2. Run: press A, count three, press B. Close to 3000?
  3. Investigate: Zara's stopwatch is this lesson's misconception: running time is not a stopwatch that starts at the press.
  4. Modify: seconds by dividing; a second event can start the timing.
  5. Mix it up: a random wait, from Pick from a list and the forever lesson's pause.
  6. Make: this is the heart of the reaction timer in the final challenge.

In class

On the slides at these points. Students can do the whole lesson on their own; these are for the room. In the deck, the Run, Modify and Make slides have the live playground in them (the tutorial link is the backup), and the notes above are in each slide's speaker notes.

The hard part (on purpose)

Seeing why the subtraction is needed. Ask what running time was when the micro:bit started, and what it is now.

When students get stuck

What you will seeA question to askThe fix
The time shown is huge, like 15000.Is start set before the time is shown?Set start to running time at the moment the timing begins.
The time shown is negative.Which way round is the subtraction?running time − start: the later reading first.
B shows 0 every time.Is start set in the same event that shows the time?Set start in A (or when the heart appears), and show the time in B.

Answers to the checks

  1. Predict: You press A when the running time is 5000, and B when it is 7500. What does B show?
    2500. A stores 5000 in start. B shows running time − start: 7500 − 5000 = 2500 ms, two and a half seconds.
  2. Trace the times: Fill in the number B shows.
    250, 3000, 180
    B shows running time minus start: how many milliseconds passed between A and B.
  3. Zara's stopwatch: Zara's B shows only running time, with no start taken away. She presses A, waits 2 seconds, presses B, and sees 14231. Why?
    running time counts from when the micro:bit started, not from A
    running time never restarts at a press. It counts from switch-on, so the time between two moments is one reading minus the other.
  4. Milliseconds to seconds: B shows 2500. How many seconds is that?
    2.5
    1000 ms is one second, so 2500 ms is 2.5 seconds.
  5. Mix it up: B clears the screen, pauses for pick random 1000 to 4000, then shows the heart. What is the longest the heart can take to appear, in milliseconds?
    4000
    pick random 1000 to 4000 can give any whole number from 1000 up to 4000, so the longest wait is 4000 ms: four seconds.

Solutions

One possible solution for each task. Other correct programs are fine.

Modify › In seconds

The program as blocks
Show as code
let start = 0
input.onButtonPressed(Button.A, function () {
    start = input.runningTime()
    basic.showIcon(IconNames.Yes)
})
input.onButtonPressed(Button.B, function () {
    basic.showNumber((input.runningTime() - start) / 1000)
})

Modify › Shake to start

The program as blocks
Show as code
let start = 0
input.onButtonPressed(Button.A, function () {
    start = input.runningTime()
    basic.showIcon(IconNames.Yes)
})
input.onGesture(Gesture.Shake, function () {
    start = input.runningTime()
    basic.showIcon(IconNames.Yes)
})
input.onButtonPressed(Button.B, function () {
    basic.showNumber((input.runningTime() - start) / 1000)
})

Make

The program as blocks
Show as code
let start = 0
input.onButtonPressed(Button.B, function () {
    basic.clearScreen()
    basic.pause(randint(1000, 4000))
    basic.showIcon(IconNames.Heart)
    start = input.runningTime()
})
input.onButtonPressed(Button.A, function () {
    basic.showNumber(input.runningTime() - start)
})

Change an egg timer

Open task: any program that does what the step asks.

Stretch and support

Stretch: Make a lap timer: B shows the time since the last B, not since A (set start again after showing).

Support: Give students the make with start already set when the heart appears, and ask them only to build the subtraction in A.

Exit ticket

start is 3000. Running time is 3750 when B is pressed. What does running time − start show, and what does it mean?

750: 750 milliseconds passed between storing start and pressing B.

What each step is for

Where it leads

Next lesson: a true/false variable, so an early press does not count. Class idea: time how long the class takes to go silent after the quiet signal.