MYP Design · Year 8 · Race day

Coding the Cars 3

This time the remote uses its buttons. Build it with two extensions, tune your car's turning speeds, then race it right round the room against the clock and against the other cars.

  • Two extensions
  • Seven steps
  • Timed races
A B battery Remote: hold A and B to go forward Car: drives what it hears
Computer accessIf your laptop will not connect to the micro:bit, sit with a classmate whose laptop has downloaded code before, and build on theirs together.

The button remote

Hold A and B together and the car drives forward. Hold A to turn left, B to turn right, and let go of both to stop. Your pair has one car and two micro:bits. Write your answers and race times on the handout as you go.

Today's steps

Open each step as you reach it. The pictures match what you will see in MakeCode.

1Your radio group is your car's numberOnly micro:bits in the same group hear each other.

Your car's number is on its label. Write it on your handout. Use it in radio set group in both programs, so your remote drives only your car, even with eight cars on the course.

2Add two extensions to each projectTPBot and radio-broadcast, in both remote and car-3.

Make two projects, remote and car-3. In each one, click Extensions and add both of these.

A. TPBot

Type tpbot and click the TPBot card, as in Cars 2. A teal TPBot drawer joins the list.

  1. Open ExtensionsAt the bottom of the block list, click Extensions.The Extensions button at the bottom of the MakeCode block list.
  2. Search for TPBotType TPBot in the search box and press Enter.The Extensions search box with TPBot typed in it.
  3. Click the TPBot cardClick the picture of the blue car.The TPBot extension card.
  4. The teal drawer appearsA teal TPBot drawer joins the list.The teal TPBot drawer in the block list, above Extensions.

B. radio-broadcast

1. Type radio-broadcast and press Enter.

The Extensions search box with radio-broadcast typed in it.

2. Click the green radio-broadcast card.

The green radio-broadcast extension card.

3. The pink Radio drawer gains a Broadcast section, holding radio send and on radio … received. These send and hear a named message, and both projects use them.

The Radio drawer with its new Broadcast section.
3Program the remoteProject remote: hold the buttons, it sends a message.

Build it

  1. Put radio set group 1 in on start and change 1 to your car's number.
  2. In forever, put if … then … else from Logic. Click its + twice to make two else if gaps.
  3. Each gap takes button A is pressed from Input. Click A to choose A+B, A or B. Put A+B first.
  4. Under each one goes radio send. To name a message, click its dropdown, choose Add a new msg… and type forward. Make left, right and stop the same way, in small letters.
  5. Finish with pause (ms) 100: the remote sends its message about ten times a second, which leaves the radio clear for the other seven cars.
  6. Download it to the micro:bit that stays in your hand.

The blocks

The remote. A+B sends forward, A sends left, B sends right, nothing pressed sends stop.
The remote. A+B sends forward, A sends left, B sends right, nothing pressed sends stop.
4Program the carProject car-3: each message sets the two wheel speeds.

Use the same group number and the same four message names as the remote: pick each name from the on radio … received dropdown. Download it to the second micro:bit and slot that one into the car.

The blocks

The car. One block for each message.
The car. One block for each message.
MessageLeft wheel, right wheel
forwardboth +50
left−50 and +50
right+50 and −50
stopstop the car

The idea. These are Cars 2's turns: they spin the car on the spot. Step 6 makes them faster.

5Drive itTry each button and write what the car did.

Switch the car on, on the floor.

You holdMessage sent
A and Bforward
Aleft
Bright
Nothingstop

Write what the car did for each one on your handout.

6Tune your turning speedsSpin, pivot or curve: time each one round a hairpin.

A race car turns while it keeps moving. The two numbers in left and right decide how.

Turnleft wheelsWhat the car does
Spin−50 and 50turns on the spot, then sets off again
Pivot0 and 60one wheel still: a tight corner
Curve30 and 70both wheels forward: a wide, fast bend

The hairpin test. Start at the end of one row of tables, drive round the end of the row and back to the start, and time it. Change one thing in car-3, download, and time it again. For right, swap the two numbers.

Your design decision. A faster forward wins on the straights and is harder to steer in the bends. The best race car balances the two.

7Race dayOne lap right round the room. Driver and timer swap each run.

The course: one lap right round the room, outside all three rows of tables, back to the start line. In your pair one person drives and one times; swap for the second run.

The rules: drive with the remote only. A stuck car is lifted back onto the course where it stopped, facing the way it was going, and the clock keeps running.

  1. 1. Time trial, run 1One car at a time, or cars set off 15 seconds apart.
  2. 2. Time trial, run 2Change one number first if you want to.
  3. 3. The heatFour cars start together: cars 1–4, then cars 5–8. First back over the line wins.
  4. 4. The finalThe top two from each heat: two laps.

Test, change one thing, test again. Work out your car's average speed on its best lap: speed = distance ÷ time, using the lap length Mr. Rawson gives you.

To go further

  • Turbo. Add a fifth message, turbo, sent while you shake the remote, that sets both wheels to 100.
  • Turn the headlights green on forward and red on stop, with Set headlight color to.
  • Design a second course with tape for another pair, and time their best lap.
The button remote and car programs are Mr. Rawson's. Block pictures and screenshots are from Microsoft MakeCode, with the TPBot extension by ELECFREAKS. The tilt remote is on Coding the Cars 2, and the robot car lessons on Coding the TPBot.