Exercise: SOS

2.16. Exercise: SOS#

Warning

This is a pair or group exercise.

  1. Pair up with a partner or form a small group

  2. Navigate to the MicroPython editor https://python.microbit.org/v/3. If you already have it open, then use that existing window or tab.

  3. Connect your micro:bit using the instructions on the previous page

  4. Decide on a channel to use in your pair or group

  5. Enter the following code into the editor and change your channel

from microbit import *
import radio

radio.config(channel=7)

while True:
    msg = radio.receive()
    if msg:
        print(msg)

    sleep(200)
  1. Flash the code to your micro:bit.

If you get stuck ask a peer or your teacher for help!

Question 1

Extend your code to:

  • Extend the code to send a message on your channel when the A button is pressed

Solution
from microbit import *
import radio

radio.config(channel=7)

while True:
    msg = radio.receive()
    if msg:
        print(msg)

    if button_a.is_pressed():
        radio.send("SOS")

    sleep(200)
Question 2

Extend your code to:

  • Extend the code to send a message on your channel when the A button is pressed

Solution

Solution is locked