Skip to content

Atividade

Hot and cold game

Intermediário | MakeCode, Python | Botões, Rádio, Visor LED | Comunicação, Tipos de dados

Primeiro passo: o projeto

O que é?

Make this fun two-player game using the BBC micro:bit’s radio feature.

O que você aprenderá:

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.

Como funciona:

  • 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. É possível escolher qualquer número de grupo entre 0 e 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.

Itens necessários:

  • Um micro:bit;
  • Editor 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

1# Imports go at the top
2from microbit import *
3import radio
4radio.config(group=47)
5radio.on()
6
7while True:
8    message = radio.receive()
9    if message:
10        display.scroll(message)
11    sleep(100)

Step 3: improve it

  1. 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.
  2. Add sound effects to the program.
  3. Use this game with a timer or step counter program to see how quickly you found the object.