← micro:bit Foundations

Again and again

Put pictures inside forever so they repeat, and use pause to set how long each one stays.

Scrolling signs at train stations and the lights on a pedestrian crossing run the same simple loop: show a picture, wait, show the next one, and start again.

Last lesson the blocks in on start ran once and the last picture stayed. A program has a second place to put blocks: forever.

PredictRead the code and say what it will do before you run anything. A wrong guess is fine: it shows you what to look for.

Predict

The program as blocks
Show as code
lesson.ts
basic.showIcon(IconNames.Heart)
basic.showIcon(IconNames.SmallHeart)
basic.forever(function () {

})

Look at which block each heart is inside, then lock in your prediction.

Ada wants a beating heart. Her hearts are in on start, and forever is empty. What will she see?

RunRun it and compare the result with your prediction.

Run

Watch for a few seconds. Does the heart beat?

The program as blocks
Show as code
lesson.ts
basic.showIcon(IconNames.Heart)
basic.showIcon(IconNames.SmallHeart)
basic.forever(function () {

})
Try it yourselfYour edits are saved in this browser.
It takes a few seconds to load. Your work in this step is kept.

InvestigateTrace how each line of code connects to what you see.

Investigate

The program as blocks
Show as code
lesson.ts
basic.showIcon(IconNames.Heart)
basic.showIcon(IconNames.SmallHeart)
basic.forever(function () {

})

Drag both show icon blocks out of on start and into forever. Keep them in the same order. The check ticks by itself as you build.

Watch the simulator for a few seconds.

Read the question first. Then add pause (in Basic) and check.

Try it yourselfYour edits are saved in this browser.
It takes a few seconds to load. Your work in this step is kept.

Move both hearts inside forever, big heart first.

This ticks by itself when your blocks do what is asked.

How many times does forever run the blocks inside it?

Ada adds pause 1000 after the small heart, inside forever. What happens?

ModifyChange the code on purpose and check the result.

Modify

Swap the small heart for a show leds block and draw your own picture.

Need a hint?

show leds is in Basic. Drag it into forever.

Another hint

Click squares in the grid to light them. Then delete the small heart.

Add a pause between the pictures. Try 500, then try other numbers.

Need a hint?

pause is in Basic. 1000 ms is one second.

Try it yourselfYour edits are saved in this browser.
It takes a few seconds to load. Your work in this step is kept.

Swap the small heart for a picture you draw with show leds.

This ticks by itself when your blocks do what is asked.

Add a pause inside forever so the beat slows down.

This ticks by itself when your blocks do what is asked.

MakeBuild something new using what you have learned. Expect a few tries; that is normal.

Make

Make an animation of three or more pictures that plays forever. Draw at least one yourself.

Ideas: a blinking eye, rain falling, a ball bouncing, a waving stick figure.

Try it yourselfYour edits are saved in this browser.
It takes a few seconds to load. Your work in this step is kept.
Need a hint?

Each picture is one block inside forever. Start with two, then add a third.

Another hint

Draw small changes from picture to picture. That is what makes it look like movement.

Make an animation of three or more pictures in forever, with at least one drawn with show leds.

This ticks by itself when your blocks do what is asked.

ModifyChange the code on purpose and check the result.

Run a shop sign

This sign scrolls a word, shows a face, then waits, again and again. Make it your own sign: change the word, swap the face, and add a frame.

Try it yourselfYour edits are saved in this browser.
It takes a few seconds to load. Your work in this step is kept.
For teachers

Students move pictures from on start into forever so they repeat, and use pause to set how long each frame stays. About 40 minutes.

Open the teacher guide: answers, solutions, slides and a worksheet.

Students will be able to

Before class

A program has two places to put blocks. on start runs its blocks once. forever runs its blocks again and again: a loop. Most surprises in this lesson come from which of the two a block is in. Try the Make yourself: three pictures in forever, one drawn with show leds.

Running the lesson

  1. Predict: most students choose 'beating over and over'. Ask: which block are the hearts inside?
  2. Run: the small heart stays. Last lesson's rule still holds: on start runs once.
  3. Investigate: students fix Ada's program in the editor; the check ticks by itself. Take a vote on the pause question before anyone adds a pause.
  4. Modify: then pause. 1000 ms is one second.
  5. Make: small changes between frames look like movement. Let students show each other.

The hard part (on purpose)

on start runs once and forever repeats. When the heart doesn't beat, ask which block the pictures are inside.

When students get stuck

Stretch and support

Stretch: Make an animation with five or more frames that tells a tiny story, such as a seed growing into a flower.

Support: Give students two show leds blocks already in forever, and ask them only to draw the pictures and add a pause.

Where it leads

Next lesson adds buttons, so the micro:bit waits for a press before it shows something. Class idea: each table designs one frame and the class joins them into one animation.

What each step is for

Now you can
Next lesson3. Wait for a pressMake the micro:bit wait for a button press or a shake, then react.