下面是我在python中使用的微位代码
因此,我想知道如何将target_x和target_y从微位1发送到第二位?
微比特1:
radio.on()
target_x = random.randint(0,4)
target_y = random.randint(0,4)
if button_a.was.pressed():
radio.send()微比特2:
radio.on()
order = radio.receive()
microbit.display.set_pixel(target_x,target_y,7)因此,我想知道如何将target_x和target_y从微位1发送到第二位?
谢谢你的回答
发布于 2017-11-17 11:18:53
我用两个微位测试了下面的代码。我在接收者上添加了一个‘除了,尝试’子句,以防消息被破坏。有更多的错误检查应该实现,以建立一个可靠的无线接口,但这回答了问题。
radio_send_randints.py
''' transmit random x and y on button push '''
import random
from microbit import *
import radio
radio.config(group=0)
radio.on()
while True:
if button_a.was_pressed():
target_x = random.randint(0,4)
target_y = random.randint(4)
message = "{},{}".format(target_x, target_y)
radio.send(message)
sleep(100)radio_receive_randints.py
from microbit import *
import radio
radio.config(group=0)
radio.on()
while True:
incoming = radio.receive()
if incoming:
try:
target_x, target_y = incoming.split(',')
except:
continue
display.set_pixel(int(target_x), int(target_y), 7)https://stackoverflow.com/questions/47340920
复制相似问题