If this is your first time, copy my premade control program ↓.
Zoe's Universal Bot Controls
Hover over the code below, click the Copy button, and paste it into your empty file.
from pybricks.iodevices import XboxController
from pybricks.parameters import Direction, Port, Stop
from pybricks.pupdevices import Motor
# Set up all devices.
try:
left = Motor(Port.A, Direction.COUNTERCLOCKWISE)
except:
pass
try:
right = Motor(Port.B, Direction.CLOCKWISE)
except:
pass
try:
weapon = Motor(Port.C, Direction.COUNTERCLOCKWISE)
except:
pass
controller = XboxController()
# The main program starts here.
try:
left.control.limits(acceleration=20000)
except:
pass
try:
right.control.limits(acceleration=20000)
except:
pass
try:
weapon.control.limits(acceleration=20000)
except:
pass
deadzone = 20
while True:
compX = 0
compY = 0
compWL = 0
compWR = 0
if (abs(controller.joystick_left()[0]) >= deadzone):
sign = 1 if controller.joystick_left()[0] > 0 else -1
compX = (abs(controller.joystick_left()[0]) - deadzone) * sign / 2
if (abs(controller.joystick_left()[1]) >= deadzone):
sign = 1 if controller.joystick_left()[1] > 0 else -1
compY = (abs(controller.joystick_left()[1]) - deadzone) * sign
if (abs(controller.triggers()[0]) >= deadzone):
sign = 1 if controller.triggers()[0] > 0 else -1
compWL = (abs(controller.triggers()[0]) - deadzone) * sign
if (abs(controller.triggers()[1]) >= deadzone):
sign = 1 if controller.triggers()[1] > 0 else -1
compWR = (abs(controller.triggers()[1]) - deadzone) * sign
if compX != 0 or compY != 0:
try:
left.run(20 * (compY + compX))
except:
pass
try:
right.run(20 * (compY - compX))
except:
pass
else:
try:
left.stop()
except:
pass
try:
right.stop()
except:
pass
try:
if compWR - compWL != 0:
weapon.run(20 * (compWR - compWL))
else:
weapon.stop()
except:
pass
2
Connect your hub to your computer
If your hub is off, press the green button to turn it on.
Make sure your hub's light is blinking.
If it's pulsing instead , press and hold the green button until it starts blinking.
Click the Bluetooth button.
Click the name of your hub, then click Pair.
When the hub is connected, the light will stop blinking and turn solid blue. The Bluetooth button icon will also change.
Troubleshooting
The hub won't light up
Make sure you've installed all 6 AA batteries. The battery holder pops out and stores 2 rows of 3 batteries each. Make sure your batteries are fully charged and facing the right directions.
The hub isn't showing up in the list
Make sure your hub is in Bluetooth mode. The blue light should be blinking, not pulsing.
If the light is off, your hub is off. Press the green button to turn it on.
If the light is slowly puling blue, your hub is running code. Press the green button to switch to pairing mode.
If it's still not showing up, reinstall the Bot Battles firmware and start over.
3
Transfer the program to your hub
Press the Play button.
The play button will turn into a loading wheel to show progress. If it gets stuck: refresh the page, reconnect bluetooth, and try again.
You only need to transfer a program to your hub once. Your hub will remember it.
Troubleshooting
The play button is grayed out
Make sure your hub is connected to your computer.
I pressed play and the loading wheel froze
Disconnect your hub by clicking the Bluetooth button in the code editor. Reconnect your hub. Load the program again.
If this still doesn't work, disconnect and reconnect Bluetooth again. Before loading the program, make any change to your program (such as adding a space to the end of a line).
If it's still not working, quit and reopen your browser, turn your hub off and on, and try again.