AdvertisementYour brand could be hereYour brand hereOn every Darslab page · students, parents and teachersinfo@darslab.comAsk for pricesPricesinfo@darslab.com
☰ Year plan · Computing

Choosing what arrives

Week 16 · 1.8 Physical computing · 3 lessons
2

Words as messages

Computing 8: Topic 1.8, pp. 173–196
GoalCompare a received word with an expected word, and know that capital letters matter.
New words
string · text, such as the word comecase-sensitive · capital and small letters count as different, so Come is not the same as comenested if · an if block placed inside the else part of another if
Explanation

A micro:bit can send words as well as numbers. radio send string sends the word, and the receiver holds it in receivedString. A receiver can compare the word with the one it expects, for example receivedString = come. The comparison is case-sensitive: Come, with a capital C, is a different string. To test for several words, put another if inside the else part. The receiver tests the first word. If that is false, it tests the second. If both are false, a final else can handle every other message, for example by showing the word. Only one branch runs for each message, and the order of the tests is the order in which they are checked.

receivedStringSame as come?
cometrue
Comefalse (capital C)
COMEfalse
come (with a space after it)false
Worked examples
Dinner sender (group 6)radio set group6on startradio send stringcomeon buttonApressedradio send stringwaiton buttonBpressedKitchen receiver (group 6)radio set group6on startshow iconyesshow iconnoshow stringreceivedStringifreceivedString=waitthenelseifreceivedString=comethenelseon radio receivedreceivedString
A dinner signal between the garden and the kitchen. Button A sends the word come and button B sends the word wait. The receiver shows a yes icon for come, a no icon for wait, and the word itself for anything else.
Who sendsWord sentReceiver shows
press Acomeyes icon
press Bwaitno icon
a third micro:bit sendsComestring Come
Tracing three messages. The third message is sent by another micro:bit, in the same group, by mistake with a capital C.
Starta word arrives (receivedString)receivedString = "come"?yesnoshow the yes iconreceivedString = "wait"?yesnoshow the no iconshow the wordEnd
The same decision as a flowchart. The second diamond is the nested if.
Class activity

Word cards (no computer). Write the words come, wait, Come and stop on separate cards. One player is the receiver with the rule from the lesson: come gives the yes sign (thumbs up), wait gives the no sign (a cross with arms), anything else gives the word read out aloud. The other player holds up the cards in a mixed order. Write the answers in a table. Check that Come with a capital letter does not give the thumbs up. Then change the rule to use the words start and finish and play again. If you have a computer or tablet, ask an adult to help you build the first receiver.

Practice
1
Using the dinner receiver, what is shown when the message is wait? What when it is stop?
Kitchen receiver (group 6)radio set group6on startshow iconyesshow iconnoshow stringreceivedStringifreceivedString=waitthenelseifreceivedString=comethenelseon radio receivedreceivedString
2
A sender sends the word Wait with a capital W. The receiver tests for wait. What is shown, and why?
3
Write the receiver blocks for this rule: the word start shows the yes icon, the word finish shows the no icon, and any other word shows the sad icon.
4
A pupil puts the test for wait before the test for come. Does this change what happens to the words come and wait? Explain.
Receiverradio set group6on startshow iconnoshow iconyesshow stringreceivedStringifreceivedString=comethenelseifreceivedString=waitthenelseon radio receivedreceivedString