← Robotics challenges

Conductor and dancers

One micro:bit plays a tune and sends a cue as each phrase starts; robots dance the move for each cue, in time.

In a drone light show, hundreds of drones move together. They do not watch each other: each one waits for a signal, then does its part of the show.

A conductor micro:bit plays a tune, one phrase at a time. As each phrase starts, it sends a cue by radio: 1 for the first phrase, 2 for the second. Every robot that hears a cue dances the move for it, so the robots keep in time with the music.

wiggle and spin are the dance moves from lesson 2. In the simulator, press A on one micro:bit: it conducts, and the other robot dances.

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
conductor.ts
function wiggle () {
    robot.motorTank(50, -50, 300)
    robot.motorTank(-50, 50, 300)
    robot.motorStop()
}
function spin () {
    robot.motorTank(50, -50, 1200)
    robot.motorStop()
}
function phraseA () {
    radio.sendNumber(1)
    music.play(music.stringPlayable("C C G G A A G - ", 120), music.PlaybackMode.UntilDone)
}
function phraseB () {
    radio.sendNumber(2)
    music.play(music.stringPlayable("F F E E D D C - ", 120), music.PlaybackMode.UntilDone)
}
input.onButtonPressed(Button.A, function () {
    phraseA()
    phraseB()
})
radio.onReceivedNumber(function (receivedNumber) {
    if (receivedNumber == 1) {
        wiggle()
        wiggle()
    } else if (receivedNumber == 2) {
        spin()
    }
})
robot.elecfreaksCuteBot.start()
radio.setGroup(1)
You press A on the first micro:bit. When does the second robot spin?

RunRun it and compare the result with your prediction.

Run

Press A on the first micro:bit. Listen to the tune (turn the sound on) and watch the second robot.

The program as blocks
Show as code
conductor.ts
function wiggle () {
    robot.motorTank(50, -50, 300)
    robot.motorTank(-50, 50, 300)
    robot.motorStop()
}
function spin () {
    robot.motorTank(50, -50, 1200)
    robot.motorStop()
}
function phraseA () {
    radio.sendNumber(1)
    music.play(music.stringPlayable("C C G G A A G - ", 120), music.PlaybackMode.UntilDone)
}
function phraseB () {
    radio.sendNumber(2)
    music.play(music.stringPlayable("F F E E D D C - ", 120), music.PlaybackMode.UntilDone)
}
input.onButtonPressed(Button.A, function () {
    phraseA()
    phraseB()
})
radio.onReceivedNumber(function (receivedNumber) {
    if (receivedNumber == 1) {
        wiggle()
        wiggle()
    } else if (receivedNumber == 2) {
        spin()
    }
})
robot.elecfreaksCuteBot.start()
radio.setGroup(1)
Try it yourselfYour edits are saved in this browser.
It opens full screen, so the robot simulator has room, and takes a few seconds to load. Esc comes back. 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
conductor.ts
function wiggle () {
    robot.motorTank(50, -50, 300)
    robot.motorTank(-50, 50, 300)
    robot.motorStop()
}
function spin () {
    robot.motorTank(50, -50, 1200)
    robot.motorStop()
}
function phraseA () {
    radio.sendNumber(1)
    music.play(music.stringPlayable("C C G G A A G - ", 120), music.PlaybackMode.UntilDone)
}
function phraseB () {
    radio.sendNumber(2)
    music.play(music.stringPlayable("F F E E D D C - ", 120), music.PlaybackMode.UntilDone)
}
input.onButtonPressed(Button.A, function () {
    phraseA()
    phraseB()
})
radio.onReceivedNumber(function (receivedNumber) {
    if (receivedNumber == 1) {
        wiggle()
        wiggle()
    } else if (receivedNumber == 2) {
        spin()
    }
})
robot.elecfreaksCuteBot.start()
radio.setGroup(1)

Watch the first robot while the second one dances.

Lily's conductor:

The program as blocks
Show as code
function phraseA () {
    radio.sendNumber(1)
    music.play(music.stringPlayable("C C G G A A G - ", 120), music.PlaybackMode.InBackground)
}
function phraseB () {
    radio.sendNumber(2)
    music.play(music.stringPlayable("F F E E D D C - ", 120), music.PlaybackMode.InBackground)
}
input.onButtonPressed(Button.A, function () {
    phraseA()
    phraseB()
})
Why does the first robot (the conductor's) not dance?

Lily changed the music to play in the background. Now her robot does all its moves at once, before the tune reaches phrase 2. Why?

ModifyChange the code on purpose and check the result.

Modify

Twinkle's third phrase is G G F F E E D - ("up above the world so high"). Add it as phraseC, with cue 3 and a new move for the robot.

Need a hint?

Duplicate phraseB and rename it phraseC. It sends 3 and plays G G F F E E D -.

Another hint

Call phraseC after phraseB on button A. Make a shuffle move (forward then back) and add else if receivedNumber = 3.

Make the robot's lights change colour with each cue, like a stage show.

Need a hint?

robot set color is in Robot. Put one at the top of each branch in on radio received, each a different colour.

Try it yourselfYour edits are saved in this browser.
It opens full screen, so the robot simulator has room, and takes a few seconds to load. Esc comes back. Your work in this step is kept.

Add the third phrase: it sends cue 3, and the robot does a new move for it.

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

The robot's lights change colour with each cue.

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 your own robot show to a tune you know (or make one up):

Ideas for notes: Mary Had a Little Lamb starts E D C D E E E -.

Try it yourselfYour edits are saved in this browser.
It opens full screen, so the robot simulator has room, and takes a few seconds to load. Esc comes back. Your work in this step is kept.
Need a hint?

Make phrase functions for your tune, each starting with send number and its own cue. Call them in order on A+B.

Another hint

Music notes: a letter for each note, - for a rest. Keep each phrase to about 8 notes. In on radio received, one branch per cue.

A show of your own: a tune in three phrases on A+B, each phrase sending its own cue to a different move.

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

Info

On a real robot

With real robots, one micro:bit (not in a robot) is the conductor and every robot in the same radio group dances. Things to notice:

For teachers

Students make a conductor micro:bit that plays a tune phrase by phrase and sends a radio cue as each phrase starts; robots dance the move for each cue, so the dance keeps in time with the music. About 50 minutes.

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

Students will be able to

Before class

This is the performance strand: lesson 2's dance moves (functions) plus lesson 7's radio. Each phrase is a function that sends its cue, then plays its notes until done. Because the music waits, the next phrase (and its cue) only starts when the last one ends, so cues arrive in time with the tune. Dancers decide what each cue means in on radio received.

Lily's show is the key slip: in background starts the music and moves on at once, so all the cues are sent together. In the simulator, two micro:bits and two robots appear (radio); pressing A on one makes the other robot dance, because a micro:bit never hears its own messages. Students need sound on (or headphones, which are not always available: the moves still show the timing).

Notes are written as letters with - for a rest, at 120 beats per minute. With real hardware, one bare micro:bit can conduct a whole class of robots in one group. Untested on real hardware: whether the robot start block errors on a micro:bit that is not in a robot (if so, the conductor's copy leaves it out). MOVE Motor classes can dance with Kitronik blocks in the same functions.

Running the lesson

  1. Predict: the key is that cue 2 waits for phrase A's music to end.
  2. Run: sound on if possible. Watch the second robot, and notice the first one stays still.
  3. Investigate: Lily's show is the background-music slip. Ask: what does 'until done' make the program wait for?
  4. Modify: phraseC is a copy of phraseB with new notes and cue 3; the dancer needs a branch for 3.
  5. Make: let students choose any tune; keep phrases short (about 8 notes) so the moves fit.
  6. Real robot (optional): one conductor, many dancers, one radio group: a class performance.

The hard part (on purpose)

Timing cues by playing each phrase until done. When moves happen at once, ask whether the music plays until done or in the background.

When students get stuck

Stretch and support

Stretch: Give each robot its own part: robots with a role variable (lead or backup) do different moves for the same cue.

Support: Give phraseC complete; students add the dancer's branch and the new move.

Where it leads

Next: the robot talks back, sending an alert to a base station. Real-world links: drone light shows, stage lighting cues, a conductor and an orchestra, synchronised swimming.

What each step is for

Now you can
Next lesson9. Report backA patrol robot sends an alert to a base station when its way is blocked, once, using a variable to remember it has already told.