Skip to content

활동

Fireflies

고급 | MakeCode, Python | LED, 라디오 | 난수, 선택 실행, 통신

1단계: 만들어 보세요.

Turn a set of micro:bits into a magical glowing swarm of fireflies using radio communication

a set of micro:bits triggering each other by radio to glow briefly

학습 내용

  • how to use radio communication between micro:bits to trigger events
  • that the micro:bit's LED display can be made brighter and dimmer
  • how to use random numbers and chance to mimic real-world behaviour

프로젝트 소개

Fireflies are insects that use bioluminescence (light made in their bodies) to communicate with each other.

This project mimics the behaviour of real fireflies using the micro:bit's radio communication feature. The Python version was created by Nicholas H. Tollervey, and the MakeCode version is based on this.

Flash the program on at least three micro:bits in the same room. Press button A on any micro:bit and you should see a 'swarm' of micro:bits lighting up as they receive a radio message. It works best in a dark room with lots of micro:bits.

Once a micro:bit has received the radio message it has a one in ten chance of transmitting its own radio message and starting another wave of glowing lights in the other micro:bits.

When the lights eventually stop, press button A on any micro:bit to restart the 'swarm' of communication.

설명

  • The program uses radio communication to send a message 'flash' when you press button A on one of the micro:bits.
  • When each micro:bit receives the message, it waits a random amount of time between 50 and 350 milliseconds. It then makes the LED display flash bright then gradually dim to mimic the glow of a firefly.
  • Next it generates a random number between 0 and 9. If the number is 0, it then sends its own 'flash' radio message, triggering more micro:bit fireflies to glow. So it has a one in ten chance of triggering more glows in other micro:bits.
  • You can use a mixture of old and new micro:bits, but they must all have either the MakeCode or Python versions of the program flashed on to them. (Radio communication works slightly differently in each programming language. MakeCode programs can't communicate over radio with Python ones and vice versa.)

준비물

  • at least 3 micro:bits, the more the better
  • micro:bit battery packs (optional)

2단계: 프로그래밍 해보세요.

3단계: 더 좋게 만들어 보세요.

  • Change the image that's displayed when the display flashes
  • Modify the code to make it more or less likely to trigger another flash event in other micro:bits. The range of random numbers could match the number of micro:bits you have: make it more likely if you have fewer micro:bits
  • Make smaller groups of fireflies using different radio group numbers. Only the micro:bits with the same group number will be able to communicate with each other.
  • Experiment with changing the power of the radio signal.
    Use the 'radio set transmit power' block in MakeCode.
    In Python use radio.config(power=7)
    Pick a number between 0 (weakest radio signal) and 7 (strongest).
    What effect does changing the radio power have?