
[Zoe Foxlin] A program tells your hub and motors how to respond to button presses. You can create your own custom program to control your bot any way you like!
Visit code.robobattles.com using Chrome or Edge.
Click the ➕ New File button.

If this is your first time, copy my premade control program ↓.
Hover over the code below, click the Copy button, and paste it into your empty file.
# Set up controller
controller = XboxController()
# Set up motors
left = Motor(Port.A)
right = Motor(Port.B)
weapon = Motor(Port.C)
# Run program loop
while True:
# Get input
compX = controller.joystick_left()[0]
compY = controller.joystick_left()[1]
compWL = controller.triggers()[0]
compWR = controller.triggers()[1]
# Accept D-Pad for drive motor control to support adaptive controllers
if Button.LEFT in controller.buttons.pressed():
compX -= 100
if Button.RIGHT in controller.buttons.pressed():
compX += 100
if Button.UP in controller.buttons.pressed():
compY += 100
if Button.DOWN in controller.buttons.pressed():
compY += 100
# Accept buttons for weapon motor control to support adaptive controller
if Button.B in controller.buttons.pressed():
compWR += 100
if Button.A in controller.buttons.pressed():
compWL += 100
# Reduce left/right input for slower turning to make bot easier to control
compX /= 3
# Control weapon motors
if compWL - compWR != 0:
weapon.go(compWL - compWR)
else:
# Triggers are not pressed, so let weapon motor spin freely
weapon.stop()
# Control wheel motors
if compX != 0 or compY != 0:
# Joystick is pressed, so move wheel motors
left.go(-compY - compX)
right.go(compY - compX)
else:
# Joystick is not pressed, so let wheel motors spin freely
left.stop()
right.stop()
Turn on your hub.
Double tap the green button. The light should start flashing blue.
Click the Bluetooth button.
Click the name of your hub, then click Pair.
When the hub is connected, the light will stop flashing and turn solid blue. The Bluetooth button icon will also change.
Turn on your hub.
Double tap the power button. The hub light should start flashing blue.
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.
If the light is slowly pulsing, your hub is running code. Double tap the green button until the light starts flashing instead.
Make sure you've installed the latest RoboBattles firmware.
If it's still not showing up, reinstall the RoboBattles firmware and start over.
Make sure the battery is charged.
Make sure your hub is in Bluetooth mode. The light should be flashing blue.
Make sure you've installed the latest RoboBattles firmware.
If it's still not showing up, reinstall the RoboBattles firmware and start over.








