1. korak: Napravi
Što je to?
Make this fun two-player game using the BBC micro:bit’s radio feature.
Što ćeš naučiti
By making this project you will learn about networks, how information is sent between electronic devices by radio, and how computers store information in different data types such as how words are stored in strings.
Kako to radi
- This is a game for two people. One person hides an object and gives the seeker clues: ‘hot’ when they are close to the object, ‘colder’ when they are moving further away, and ‘warmer’ when they are getting closer.
- Usually, this game is played by shouting the words ‘hot’, ‘colder’ and ‘warmer’ but in this version of the game the words are sent by radio from one micro:bit to another and appear on the LED display.
- There are two programs, one for the hider and one for the seeker.
- First, each program sets the radio group to 47. Groups are like channels, so any micro:bit using the same group will get the message. Za broj grupe možeš koristiti bilo koji broj od 0 do 255.
- The hider presses button A to send the message ‘warmer’, presses button B to send the message ‘colder’ and presses buttons A and B together to send the message ‘hot’.
- The micro:bit can send messages as numbers or text. We’re using text messages in this project, so make sure you use radio blocks that refer to strings rather than numbers or values.
- In computing, a string is a sequence of characters that can contain letters, numbers, symbols, and spaces.
- When the seeker's micro:bit receives a radio message, it shows the string received on its LED display. The strings are also displayed on the hider’s micro:bit.
Što ti treba
2 micro:bita- Uređivač za MakeCode
- battery packs (recommended)
Step 2: code it
Hider code
1# Imports go at the top
2from microbit import *
3import radio
4radio.config(group=47)
5radio.on()
6
7while True:
8 if button_a.is_pressed() and button_b.is_pressed():
9 radio.send('HOT!')
10 display.scroll('HOT!')
11 elif button_a.is_pressed():
12 radio.send('warmer')
13 display.scroll('warmer')
14 elif button_b.is_pressed():
15 radio.send('colder')
16 display.scroll('colder')
17 sleep(100)
Seeker code
Step 3: improve it
- Edit the program so that different words appear instead of 'hot', 'colder' and 'warmer'. For example, you could use the words for 'hot', 'colder' and 'warmer' in a foreign language you are learning.
- Add sound effects to the program.
- Use this game with a timer or step counter program to see how quickly you found the object.
This content is published under a Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) licence.