1

我必须编写此代码,以便两个 microbits 可以相互交互。但我无法测试它,因为我只有一个。有没有办法通过一些在线网站/插件/东西来测试这段代码?代码: https ://pastebin.com/N0FirrsD (此代码将收到并采取相应措施)

from microbit import *
import radio

#Pin 0 is the left motor
#Pin 1 is the right motor
#Pin 3 is a buzzer

Starten = false

while Starten == false:
    if button_a.is_pressed():
        Starten = true
    else:
        microbit.display.scroll('Druk op A')
        
radio.on()
radio.config(channel=56)
radio.config(power=7)

while Starten == true:
    Commando = radio.receive()
    
    if Commando == "vooruit":
        pin0.write_digital(1)
        pin1.write_digital(1)
        
    if Commando == "remmen":
        pin0.write_digital(0)
        pin1.write_digital(0)
        
    if Commando == "links":
        pin0.write_digital(0)
        pin1.write_digital(1)
    
    if Commando == "rechts":
        pin0.write_digital(1)
        pin1.write_digital(0)
        
    if Commando == "toeter":
        pin3.write_digital(1)
        sleep(2000)
        pin3.write_digital(0)
        
    if button_b.is_pressed():
        Starten = false:

https://pastebin.com/SPbLtWGr(此代码将发送命令)

from microbit import *
import radio


Starten = false

while Starten == false:
    if button_a.is_pressed():
        Starten = true
    else:
        microbit.display.scroll('Druk op A')
        
radio.on()
radio.config(channel=56)
radio.config(power=7)

while Starten == true:
    if accelerometer.is_gesture("up"):
        radio.send("vooruit")
        
    if accelerometer.is_gesture("down"):
        radio.send("remmen)
        
    if accelerometer.is_gesture("left"):
        radio.send("links")
        
    if accelerometer.is_gesture("right"):
        radio.send("rechts)
        
    if button_a.is_pressed():
        radio.send("toeter)
4

1 回答 1

2

一种选择是编写一些存根模块(microbitradio等),让您可以在常规 Python 下测试您的代码。这将有助于清除基本的语法错误(例如,您的一些打印语句缺少结束引号)。

您可以使用文件或 FIFO 来模拟无线电和 GPIO 功能。

于 2020-04-23T18:20:15.033 回答