Try This: Condense the Input
Let’s try reducing the input to int line count from six to three.
- Set the cyber:bot board’s PWR switch to 0.
- Use the micro:bit Python Editor to open terminal_controlled_bot_tethered_intro.
- Set the project name to terminal_controlled_bot_tethered_try_this.
- Replace these six lines:
text = input("Enter left speed: ")
vL = int(text)
text = input("Enter right speed: ")
vR = int(text)
text = input("Enter ms to run: ")
ms = int(text)
…with these three lines:
vL = int(input("Enter left speed: "))
vR = int(input("Enter right speed: "))
ms = int(input("Enter ms to run: "))
- Check your modified script, it should resemble the example below.
- Click Save and Send to micro:bit.
- Repeat the tests you did with terminal_controlled_bot_tethered_intro and verify that this modified version runs the same as the original.
Example script: terminal_controlled_bot_tethered_try_this
# terminal_controlled_bot_tethered_try_this
from cyberbot import *
sleep(1000)
print("\nSpeeds are -100 to 100\n")
while(True):
vL = int(input("Enter left speed: "))
vR = int(input("Enter right speed: "))
ms = int(input("Enter ms to run: "))
bot(18).servo_speed(vL)
bot(19).servo_speed(-vR)
sleep(ms)
bot(18).servo_speed(None)
bot(19).servo_speed(None)
print()