Foundation First Program: Author a Button
Next →
Lesson · Foundation

First Program: Author a Button

Students open the robot's receiver in MakeCode and give a button a new behavior by editing the dispatch skeleton — their first program.

Duration90 min ProgrammingMakeCode blocks — modify DevicesYes Prep15 min Segments7

Opening Concept

You can change what the robot does. The robot runs a program called the receiver. It’s built so that driving always works — that part runs on every radio message, outside the buttons — and each button just sets a light and does one action. Today you copy the worked example into an empty button slot and make it your own. Because driving is separate, you can’t break it.

Run Sheet

  1. 0:00–0:08 Recap & hook

    Last time you drove it. Today you change what it does.

    • Show a button doing something new — a sound, an image, the gripper.
  2. 0:08–0:23 Open & flash the baseline

    Open the receiver share link, connect over WebUSB, and flash the unchanged project.

    • Confirm driving still works after flashing.

    Watch for: Charge-only USB cables power the board but won’t flash it. Use a data cable.

    If they're stuck: Use Chrome or Edge, click Connect device, and pick the micro:bit.

  3. 0:23–0:38 Read the skeleton

    Walk the dispatch structure together.

    • Each button sets a light and does an action (D and E are worked examples — open/close gripper).
    • Driving runs on every message, outside the if/else — so editing a button can’t break it.
    • C and F are empty slots waiting for the student’s first code.
  4. 0:38–1:03 Author a button Modify

    Copy the worked pattern into C or F: make the button do something visible, and set its light.

    • Options: play a sound, flash an image, close the gripper, trigger a dance move.
    • Flash and test on the robot.

    Watch for: Edited but didn’t flash (’nothing changed’) — confirm they clicked Download and the robot re-flashed.

  5. 1:03–1:15 Iterate & extend

    Tweak it; fill the second empty slot if time allows.

    • Notebook: what did your button do versus what you expected?

    If they finish early: Chain two actions in one button (light + sound + move), or design a ‘signature’ light pattern.

  6. 1:15–1:25 Share-out

    Three or four students show their button.

    • Celebrate the range — every student made the robot do something different.
  7. 1:25–1:30 Wrap-up & pack

    Save the share link, power down, store devices.

    • Remind students their program lives at the share link — they’ll build on it next time.

Materials

Engineering Connection

Build (modify)

This is the first rung of the authorship ladder: students modify provided code. The receiver skeleton is a scaffold — driving is decoupled and unbreakable, and the label-lights make it obvious which button fired. Students get a real win (the robot does something they chose) without having to write a program from scratch yet.

Troubleshooting

Edited the program but nothing changed
They didn’t flash. Click Download and confirm the robot re-flashed; check the right device is selected in WebUSB.
Pairing or driving broke after editing
They likely opened the transmitter by mistake. Re-open the receiver share link — students only edit the receiver.
The new action runs all the time, or driving stopped
Code went in the wrong place. Keep the action inside the C/F button branch; leave the driving line where it is.
Can't tell whether the button fired
Set a distinct light color in the branch first — the headlight is a built-in ‘did it run?’ check.
WebUSB won't connect
Use Chrome or Edge, a data cable, then Connect device and pick the micro:bit.