1

I have to make this code so two microbits can interact with each other. But I can't test it since I only have one. Is there a way to test this code through some online website/plugin/something? Code: https://pastebin.com/N0FirrsD (This code will receive and act accordingly)

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 (This code will send commands)

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)
VedantK
  • 9,728
  • 7
  • 66
  • 71
Nick
  • 51
  • 1
  • 5

1 Answers1

2

One option is to write some stub modules (microbit, radio, etc) that will let you test your code under regular Python. This will help flush out basic syntax errors (e.g., several of your print statements are missing a closing quote).

You can use files or FIFOs to simulate the radio and GPIO features.

larsks
  • 277,717
  • 41
  • 399
  • 399