Your Turn: Handle Transmitter Exceptions
The same simple approach for prototyping that was used in tethered control can also be used here.
Example script: terminal_bot_controller_wireless_your_turn
- Click Open and select terminal_controlled_bot_wireless.
- Set the project name to terminal_bot_controller_wireless_your_turn.
- Update the script as shown below, then click Save.
# terminal_bot_controller_wireless_your_turn
from microbit import *
import radio
radio.on()
radio.config(channel=7,length=64)
sleep(1000)
print("\nSpeeds are -100 to 100\n")
while True:
try:
vL = int(input("Enter left speed: "))
vR = int(input("Enter right speed: "))
ms = int(input("Enter ms to run: "))
dictionary = { }
dictionary['vL'] = vL
dictionary['vR'] = vR
dictionary['ms'] = ms
packet = str(dictionary)
print("Send: ", packet)
radio.send(packet)
print()
except:
print("Error in value entered.")
print("Please try again. \n")
- Click Show serial, then click inside the serial monitor.
- Try valid numbers and verify that it still works.
- Try entering characters like ABC for one of the prompts, and verify that it displays the helpful “Error in value entered. ” and “Please try again. ” messages.
