Mood Radio

This project uses the radio to share your mood with other micro:bits. When you press
A, your friends will see a smiley face. When you press B, they will see a frowny face.Sending a smiley
The micro:bit can’t understand mood but it is pretty good with numbers. In fact, it can send numbers between micro:bits using the radio antenna, just like a phone can send text messages.
Let’s add blocks that send a number when button
A is pressed. We assume that 0 is the “mood code” to send for smiley.
Receiving a smiley
We add a
||radio:on radio received|| block that will run code whenever a new “mood” message comes in. The receivedNumber variable contains the numeric value that was sent. Since we’ve decided that 0 is smiley, we add a conditional ||logic:if then|| statement to show this icon.
Sending a frowny
Adding another mood to our messaging app done in a similar way. We decide that the “mood code” of
1 means frowny. We can add a B button event that sends that code.
If the
||radio:on radio received|| block, we add another conditional ||logic:if then|| statement to handle the frowny “mood code”.
That’s it. Download your code to multiple micro:bits and try it out!
Challenges
Try adding a new code and use the
||input:on shake|| event to send it.Full sources

没有评论:
发表评论