廣播互動

廣播傳送訊息 接收訊息

讓孩子玩廣播

學習重點

接收程式

發射程式

接收 + 發射 程式

形成半雙工通訊

import radio
from microbit import *

radio.on()
radio.config(length=32, queue=3, channel=7, power=7, data_rate=radio.RATE_1MBIT)
while True:
  if radio.receive() == '1':
  display.show(Image.HEART)
  sleep(100)
  display.show(Image.HEART_SMALL)
  sleep(100)
  display.clear()
 if radio.receive() == '2':
  display.show(Image.HAPPY)
  sleep(100)
  display.show(Image.SMILE)
  sleep(100)
  display.clear()
 if button_a.is_pressed():
  radio.send(str('1'))
  display.show(str('A'))
  sleep(100)
  display.clear()
 if button_b.is_pressed():
  radio.send(str('2'))
  display.show(str('B'))
  sleep(100)
  display.clear()

廣播 螢火蟲

用 Microbit 透過 python 也能玩 螢火蟲 歐耶!!