Skip to content

Atividade

Hot potato game

Intermédio | MakeCode, Python | Botões, Coluna de Som, Ecrã LED | Aleatoriedade, Entrada/Saída, Iteração, Variáveis

Passo 1: Faz tu mesmo

O que é isto?

Turn your micro:bit into a ‘hot potato’ by coding it to become a random timer. To play the game, pass the ‘micro:bit potato’ on to the next person before the timer goes off.

Como jogar

Press button A and pass the ‘hot potato micro:bit’ around a circle of players. Se emitir o som triste e aparecer uma cruz enquanto a estás a segurar, então estás fora do jogo. The last person left is the winner.

Como funciona

Este projeto usa o botão A como entrada para iniciar uma série de eventos.

First the ‘timer’ variable is set to a random number between 5 and 15, and a chessboard image appears on the LEDs.

Depois, a variável ‘timer’ começa a contagem decrescente, diminuindo 1 a cada segundo, até chegar a 0.

The 'while loop' helps us shorten the code. While the ‘timer’ variable is above zero, the section of code counting down keeps repeating, but as soon as the ‘timer’ variable reaches zero, the loop stops.

Put the code on a micro:bit and attach a battery pack to turn it into a ‘hot potato micro:bit’.

Do que é que precisas

  • micro:bit (ou simulador MakeCode)
  • Editor MakeCode ou Python
  • suporte de pilhas

Passo 2: Cria o teu código

1from microbit import *
2import music, random
3
4while True:
5    if button_a.is_pressed():
6        timer = random.randint(5, 15)
7        display.show(Image.CHESSBOARD)
8        while timer > 0:
9            timer -= 1
10            sleep(1000)
11        display.show(Image.NO)
12        music.play(music.WAWAWAWAA, wait=False)
13        audio.play(Sound.SAD)
14        

Passo 3: Melhora-o

  • Muda a duração do temporizador para se adaptar a diferentes tarefas ou altera-o de aleatório para um tempo específico.
  • Modifica o programa para que apareça um ícone diferente ou a tua própria imagem quando carregas no botão A.
  • Change the sound to a happy/positive sound to indicate when someone has ‘won’ something.
  • Utiliza-o em diferentes contextos, por exemplo, para praticar a ortografia ou as tabuadas, ou como uma contagem decrescente na sala de aula.