All pages
Powered by GitBook
1 of 5

Loading...

Loading...

Loading...

Loading...

Loading...

Quests

Complete quests to earn XP and level up your skills!

💻 = Coding required

Cover
Sinkhole Patrol

Code an autonomous robot to keep scrap out of a sinkhole. 💻

🏆 350 XP

Cover
Dance Video

Code a robot to perform in a dance video. 💻

🏆 250 XP

Cover
Martinez Twins vs VentureState

Code a control program for a racing robot to save a local team. 💻

🏆 400 XP

Cover
Big Break

Code custom controls to compete in the RoboBattles. 💻

🏆 350 XP

Martinez Twins vs VentureState

  • 🏆 400 XP

[Zoe Foxlin] I need your help. Like, right now. Meet me at the abandoned test track east of town. We've got a situation. Bring a robot with two wheel motors, like the . I'll explain why when we get there.

No time to waste. Here's the deal. Have you met the Martinez twins? They're a couple of up-and-coming robot builders who've been running this incredible recycling program across town. Free robot repair clinics, big collection of salvaged parts, the works.

Here's the problem. VentureState showed up last week. A big land corporation. They're trying to shut down the twins' program so they can take over the building. The twins challenged them to settle it with a race. Custom robot controls only. Fastest robot takes it. If the twins win, VentureState backs off. If they lose...

The twins' robot is practically perfect. One of the best designs I've ever seen. But their coder quit yesterday. VentureState offered them a job they couldn't refuse. 😠 So this robot — which again, PRACTICALLY PERFECT — has no control program. It's useless.

I need your help creating a program that can take down VentureState's store-bought robot. The race is tonight. Will you help? Great.

Make sure your robot has two wheel motors, like the Purrmenator. Plug the left motor into port A and the right motor into port B.

1

Let's start with the code we made for our dance video robot.

This robot uses the joystick to spin on command. But the Martinez Twins don't need a dancing robot. They need a robot they can steer all over a racetrack.

We started with the motor on the left. We control it with the left joystick.

Next we'll do the motor on the right. We should control this one with the right joystick.

Let's start by copying the motor code we already have. Here's where we set up the motor.

The motor on the left is plugged into the hub's port A. So when we set up the new motor in our code, we'll want to use Port.B instead of Port.A. This is called a parameter. Let's copy this line and change the port parameter.

2

Hmm, I already see a problem here. We're using the motor variable twice.

The first line stores motor A in motor. But then the second line replaces it with motor B. Now motor A is lost. We have no way to control it.

We'll need to use two different variables by giving them different names. What should we call them? A variable can have basically any name, as long as it:

  • Only uses letters, numbers, and underscores _

  • Doesn't start with a number

We COULD name the second variable toilet. 🚽 But the code will be easier to understand if the variable names actually makes sense. So flush that idea. We'll call them motorA and motorB instead.

3

Much better. We'll need two speed variables as well. Copy the line where we set the motor speed. Rename the variables speedA and speedB .

4

We want speedB to come from the right joystick. So let's change joystick_left to joystick_right.

5

Lastly, let's copy our motor rotation code and use the new variables.

6

The program should look like this.

Load it up. Push both joysticks all the way up. Both wheels will turn, and your robot will drive straight ahead. We did i— oh wait.

7

Problem! What's going on here?

The motors are running in different directions! Nooooo!

This is because the motors are facing opposite directions from each other. We want our robot to move forward when we press both joysticks up. So we need to make motor A rotate the opposite direction.

Remember on our sinkhole robot how we switched motor direction by adding - to the speed value? Well, we can do the same thing here with math. We multiply speedA by -1. To multiply, we use the * symbol.

8

If you haven't used negative numbers before, don't worry about how this works. Just know that you can always multiply by -1 to flip a motor's direction.

Here's the final code.

You know the drill. Load it up and enjoy your fully steerable robot!

Push both joysticks up to drive forward. Push both joysticks down to drive backward. Push the joysticks in different directions to turn.

9

Let's make sure this program works! Design an awesome race course with crazy turns and obstacles to avoid.

10

Steer your robot through the course as fast as you can. If you have a friend or teammate with another robot, challenge them to race.

11

Amazing. I couldn't have done it without you.

Wait, what time is it!? I have to get this program over to the Martinez Twins. VentureState's robot won't stand a chance.

Now that you know how to code, you can start experimenting with custom joystick controls for your own robot designs. Later on I'll show you how to use controller buttons.

Rewards

Fastest Robot Takes It

Purrmenator
# Set up controller
controller = XboxController()

# Set up motor
motor = Motor(Port.A)

while True:

    # Set motor speed
    speed = controller.joystick_left()[1]

    # Rotate motor
    motor.go(speed)
# Set up motor
motor = Motor(Port.A)
# Set up motor
motor = Motor(Port.A)
motor = Motor(Port.B)
# Set up motor
motorA = Motor(Port.A)
motorB = Motor(Port.B)
    # Set motor speed
    speedA = controller.joystick_left()[1]
    speedB = controller.joystick_left()[1]
    # Set motor speed
    speedA = controller.joystick_left()[1]
    speedB = controller.joystick_right()[1]
    # Rotate motor
    motorA.go(speedA)
    motorB.go(speedB)
# Set up controller
controller = XboxController()

# Set up motor
motorA = Motor(Port.A)
motorB = Motor(Port.B)

while True:

    # Set motor speed
    speedA = controller.joystick_left()[1]
    speedB = controller.joystick_right()[1]

    # Rotate motor
    motorA.go(speedA)
    motorB.go(speedB)
    # Rotate motor
    motorA.go(speedA * -1)
    motorB.go(speedB)
# Set up controller
controller = XboxController()

# Set up motor
motorA = Motor(Port.A)
motorB = Motor(Port.B)

while True:

    # Set motor speed
    speedA = controller.joystick_left()[1]
    speedB = controller.joystick_right()[1]

    # Rotate motor
    motorA.go(speedA * -1)
    motorB.go(speedB)

Another One

Math

The Race

Sinkhole Patrol

Rewards

  • 🏆 350 XP

[Zoe Foxlin] OOF. I'm so sorry. 😮‍💨 I wasn't looking where I was going. Gotta run, we've got a situat— oh, it's you! You have no idea how glad I am to see you, and - ugh, this RAIN! Look, just run with me and I'll explain.

Stardust Springs was a mining town back in the day. There are old mining tunnels everywhere under the industrial district. Nobody's supposed to worry about the tunnels. "Don't worry about the tunnels." Turns out we should've worried about the tunnels.

This storm has opened up a sinkhole right next to a scrap storage building. And it's growing. Like, faster than my laundry pile.

Scrap is starting to wash into the sinkhole. Once it's down there, we can't recycle it. It'll be lost forever in the tunnels, polluting the ground for decades.

The good news: I've got a team of robot battlers coming in as fast as they can to break down the scrap before it washes away. The bad news: they can't get through this storm. They won't make it until tomorrow morning. By then it'll be too late.

We need a robot to buy us some time. A vehicle that can patrol around the edge of the sinkhole all night to prevent scrap from getting washed in. Like a guard dog for scrap.

You've been working on crafting a robot, haven't you? That may be our only hope. Bring it. I'll help you program it to patrol the sinkhole. Just make sure it has wheel motors, like the . And double check that the left motor is plugged into port A on your hub. Otherwise our program will crash.

Oh wow, this sinkhole is even worse than I thought. We don't have much time to whip up our code.

Here's a secret. Come in close. I'M BAD AT CODING! Here's another secret. WHO CARES! It's never ever stopped me from programming my robots to do exactly what I want.

It's like... okay, you know how some people are good at making sandwiches? They can slap one together in 30 seconds. Other people have to spend 5 minutes looking up recipes and arranging all the ingredients. Well, both methods end up with a sandwich! One's not more "sandwich-y" than the other.

Coding is the same way. If you're good at it, you can do it fast. If you're bad at it, you might get stuck sometimes and have to search online for answers. That's fine! As long as you're creative, you'll always get there.

You don't have to be a chef to make a sandwich, and you don't have to be a "coder" to code a robot. I'm NOT a coder. I just use code sometimes to make my robots do awesome stuff. This is one of those times! We'll get it done together.

Before you start cooking, you have to decide what you want for lunch. (I'M HUNGRY, OKAY?) And before you start coding, you have to decide what you want your robot to do.

I'm thinking if we just get one wheel motor to rotate, that'll make the robot drive in circles around the sinkhole. Let's do it. Rotate motor.

Start by bringing up a blank program in Pybricks. Visit using Chrome or Edge.

Pybricks uses a programming language called Python. 🐍 And now... to code!

Rotate motor. Rooootaaaaaate motor. Aaaand I'm stuck. No problem. That's what the internet is for.

I searched online for "pybricks rotate motor example" and found this code.

Does it work? Bro, I don't know! Let's load it up and see what happens.

  1. Hover over this code and click the "Copy" button.

  2. Paste it into Pybricks.

  3. Load the program onto your hub. If you forgot how, see .

  4. Connect your controller to your hub. If you forgot this too, see

Okay, the controller is connecting, and...

STOP THAT SPINNING ROBOT! Pounce on it before it falls into the sinkhole! Press the green button!

Close call there. We wanted a rotating motor, and we got a rotating motor. But I don't know if it's rotating with enough speed. We're making a scrap fighting machine, not a microwave.

Let's take a look at the code and see what's going on. That way we can figure out what to change to make the motor rotate with more speed.

Here's the very first line.

This is a comment. A comment begins with a hashtag #.

Imagine you're baking a cake, and you have a recipe with steps to follow. Someone wrote a little note in the recipe: "Be careful not to spill the flour!" That note isn't part of the recipe. But it's very helpful, because it makes the recipe easier to follow.

Comments are just like that. They're useful for explaining what code does. They make your code easier to follow.

You can write anything in a comment. They're only for humans. The computer completely ignores comments when running the program. Just like I ignore Insta comments from my ex. (#sorrynotsorry)

Let's look through the other comments in this program. Maybe we can find a hint about increasing our motor's speed.

Well this one looks promising.

This comment helpfully explains what the next line does. Spoiler alert: it sets the motor's speed.

I bet we can make our motor rotate faster by increasing this number. Try changing it from 20 to 100. Load the new code onto your hub and turn on your controller again. This time, maybe hold onto your robot first...

WOW. Now we're cooking. Press the green button to stop the program before we plow through a wall or something.

When I'm not sure what code does, sometimes I just tinker around. I'll change a number and see what happens, like we did here with the speed number. It's a great way to figure out how things work.

Speaking of tinkering... there's just one more problem. This robot is driving backwards! We need to make the motor rotate in the other direction. We can do this by adding a minus sign. Change the number from 100 to -100. Like this.

The full code should look like this.

Now set your robot up on the edge of the sinkhole and try running that program.

YESSSS. SUCCESS!

If you want to make this robot an even better scrap defender, craft an arm for it that drags along the ground and pushes scrap away from the sinkhole. You can sprinkle some spare scrap around it to test if the arm works.

Once you're satisfied, fire that robot up and let it patrol! We'll check on it after the storm is over.

IT WORKED! I can't believe it. Sinkhole patrol robot saves the day. And look, here come the other robot battlers to break down all the scrap!

Next time you need to make a motor turn, you'll have an example to copy from. You'll make that sandwich — I mean program — even faster. Stop by my garage any time if you ever need more coding help.

.

Bad at Coding

Rotaaaaate Motor

Comments

Tinkering

Scrap Scoop

Finale

Purrmenator
code.pybricks.com
Custom Controls
1
2
3
4
5
Controlling Your Bot
# Set up controller
controller = XboxController()

# Set up motor
motor = Motor(Port.A)

# Set motor speed
speed = 20

while True:

    # Rotate motor
    motor.go(speed)
# Set up controller
# Set up controller
controller = XboxController()

# Set up motor
motor = Motor(Port.A)

# Set motor speed
speed = 20

while True:

    # Rotate motor
    motor.go(speed)
# Set motor speed
speed = 20
# Set motor speed
speed = -100
# Set up controller
controller = XboxController()

# Set up motor
motor = Motor(Port.A)

# Set motor speed
speed = -100

while True:

    # Rotate motor
    motor.go(speed)

Dance Video

Rewards

  • 🏆 250 XP

[Stewskee] WHAT. IS. UP! YOUR BOY STEWSKEE HERE WITH THE COLLAB Y'ALL BEEN BEGGING FOR. THAT'S RIGHT. I'M HERE WITH THE CREATOR OF THE SINKHOLE PATROL ROBOT. WHAAAAT.

Psst... hey... lean into this shot for the intro. Look real serious. Yea alright. Got it. Appreciate it.

You want a selfie or something? Wait. You don't know who I am? FOR REAL? Braeden? Braeden Stewart? @stewskee? 2 million followers? I guess you're not one of 'em.

Check this out. So I'm livestreaming during that insane storm. I turn a corner and there's this GIANT SINKHOLE. And this robot is RIPPING circles around it. WHAT.

Chat goes nuts. The clip blows up. My followers DOUBLE. Everyone's DM'ing me about this robot.

The algorithm's begging for more sinkhole robot. Gotta get more content out of it. So I got this idea.

DANCE VIDEO.

Picture this. We drop a track. Your robot dances to it with its signature spin moves. ARE YOU KIDDING ME. 5 million followers EASY.

You'll do alright too. You'll get your name out there. Launch your robot crafting career. Inspire more builders to get started.

Meet me here tomorrow and we'll shoot. Actually - this background is TRASH. Meet me over there instead. Just one thing. Make sure your robot can spin with the beat. The dance has gotta be perfect.

[Zoe Foxlin] Robot code? For a dance video!? With Stewskee!?! Omg yes. I'm fangirling right now.

Just like last time, make sure you've got a robot with wheel motors, like the . The left motor has to be plugged into port A.

Let's start with the old code we found online for the sinkhole robot.

We turned this into a mean patrolling machine by changing its motor direction and speed. But for a dance video, you don't need a self-driving robot. You need a robot you can steer with your Xbox controller to make it whip back and forth with he music.

We'll need to understand more about the code so we can figure out what to change.

Last time we just changed the speed number. What's actually going on when we do that? Let's look at the line.

  • speed is a variable. A variable is like a box for storing things.

  • = tells the computer to store something in the box.

  • 20 is a number. 🤯🤯🤯

So this line stores the number 20 in a variable named speed.

🤔 If we're bothering to store that number 20, it probably means we're using it again later. Let's look through the rest of the code. See if you can find another line where the variable speed appears.

There it is, right at the end.

Thanks to the comment, we know what this line does. It rotates the motor. And it uses our speed value for the rotation speed.

Any time we write the variable speed, the computer uses the value stored inside it. We know that speed is storing the number 20. So when we write...

... the computer basically does

What's up with this motor thing? Where does it come from? Let's look earlier in the code. See if motor appears anywhere else.

There it is.

Looks like motor is another variable. But instead of storing a number like 20, we're storing something else: Motor(Port.A).

  • Motor(Port.A) is an object. It represents the motor plugged into hub port A.

So this line stores a motor object in the variable motor. And we use this motor variable later on to actually rotate the motor, just like we did with the speed variable.

We want our Xbox joystick to control the rotation speed. So instead of storing 20 or 100 or whatever in the speed variable, we want to store the joystick's position.

First we'll need to set up our controller. That was already done in the code we found online. Check out this line.

Looks a lot like the line where we set up the motor. And it works almost the same way.

  • controller is another variable.

  • XboxController() is another object. This one represents our controller.

So we've stored the controller. Hmm, how do we get its joystick position? Joystick position. Joyyyyyystick position. I'm stuck again.

Oh wait, I think I've done this before! When I get stuck on a coding problem, I try to remember if it's something I've coded before. That way I can look at my old programs, instead of trying to find a random example online.

I've definitely written joystick code for other robots. Let me dig through some old files. There it is!

Good thing I left a comment. Thanks, old me. 🤝 So this code will get the joystick's vertical (up/down) position from our controller.

On the line where we set speed, let's replace the 20 with my joystick code.

The final code should look like this.

Load the program onto your hub and turn on your controller. Once your controller connects, try moving the left joystick up and down.

And away we gooooo.... hmm. It's not working.

What the heck. It really seems like this should work.

When I can't figure out why my code isn't working, sometimes I ask an AI chatbot. I pasted in all the code, and I asked:

why can't I control the motor speed?

It said:

speed is only being set once, right when the program starts. Move it inside the "while loop" so it's set continuously from the joystick.

Ah ok! Good chatbot. 🫳🐶 Take a look at these lines at the end of the program.

This is called a "while loop." The line while True: starts the loop. The code inside it will run over and over. It repeats until humanity goes extinct. Or until your hub runs out of battery. Whichever comes first.

The chatbot says we need to set our speed variable inside the while loop. Let's move it inside.

Note that all the lines inside the loop are indented. That's not an accindent. 😂 The indents tell the program that these lines are "inside" the while loop.

The full program should look like this.

Load it up. Connect your control, and give that left joystick a push!

Remember when we first saw this program? It looked like gibberish. Well now it actually makes some sense! Let's look at it one last time from the start.

We know this. What does it do?

Next! What does this do?

Next again! We know these lines too. Remember what they do?

That's the whole thing! We set up a few variables. We run the motor in a loop. Not so scary.

It's fine if you're still a little confused. The important thing is that the code works. And next time you'll be able to whip up your code even faster!

Now take this masterpiece back to Stewskee. I'll just be sitting here refreshing until the dance vid drops.

[Stewskee] There it is, THE sinkhole patrol bot. I mean, the chassis SLAPS. But the decorations are kind of... basic? No offense. Just, my viewers expect a certain aesthetic.

Find some scrap and take a sec to decorate this thing. Don't go overboard though. Just give it a vibe. In a few minutes this lighting will be trash.

WHAAAAT. I can barely recognize it. That's FIRE.

YOU READY?

  1. Blast your favorite beats.

  2. Turn on your bot and connect your controller.

  3. Drop that signature SPIN. Move the joystick up and down to step back and forth with the beat.

  4. Got a phone? Shoot it, or ask a buddy.

NO WAY. This is LITERALLY THE CLEANEST bot choreo EVER.

I'm dropping this tonight. The numbers are gonna be CRAZY.

Get ready. Your phone's gonna blow up. This time tomorrow you'll be a legend. Everyone in Stardust Springs is gonna know your name.

Big Break

  • 🏆 350 XP

[Mayor Ishii] You've heard the news, right? You haven't!? Do you even check your DMs!? We're down a competitor for tonight's RoboBattles! The headline match was supposed to feature Ben Carr, one of our volunteer firefighters. But a wildfire sprung up a few hours ago. His whole squad got called out to fight it. I've been scrambling to find someone to take his place.

I know you haven't been here long, but Zoe tells me you're a total natural. This could be your big break. Do you think you can put a robot together in time? Oh, one very important thing. Tonight's battle is custom controls only.

Hurry over to Zoe's Garage and she can help you design your very own control program.

If you've got permission, POST THIS THING. #BotBattles

Best Recycler Takes It

Variables

Objects

Xbox Joystick

While Loop

From the Top

Make it Pop

Fire

Legend

Purrmenator
1
2
3
4
5
6
7
8
9
10
# Set up controller
controller = XboxController()

# Set up motor
motor = Motor(Port.A)

# Set motor speed
speed = 20

while True:

    # Rotate motor
    motor.go(speed)
speed = 20
# Set up controller
controller = XboxController()

# Set up motor
motor = Motor(Port.A)

# Set motor speed
speed = 20

while True:

    # Rotate motor
    motor.go(speed)
    # Rotate motor
    motor.go(speed)
    motor.go(speed)
    motor.go(20)
# Set up controller
controller = XboxController()

# Set up motor
motor = Motor(Port.A)

# Set motor speed
speed = 20

while True:

    # Rotate motor
    motor.go(speed)
# Set up motor
motor = Motor(Port.A)
# Set up controller
controller = XboxController()
# Get joystick's vertical position
controller.joystick_left()[1]
# Set motor speed
speed = controller.joystick_left()[1]
# Set up controller
controller = XboxController()

# Set motor speed
speed = controller.joystick_left()[1]

# Set up motor
motor = Motor(Port.A)

while True:

    # Rotate motor
    motor.go(speed)
while True:

    # Rotate motor
    motor.go(speed)
while True:

    # Set motor speed
    speed = controller.joystick_left()[1]

    # Rotate motor
    motor.go(speed)
# Set up controller
controller = XboxController()

# Set up motor
motor = Motor(Port.A)

while True:

    # Set motor speed
    speed = controller.joystick_left()[1]

    # Rotate motor
    motor.go(speed)
# Set up controller
controller = XboxController()
# Set up motor
motor = Motor(Port.A)
while True:

    # Set motor speed
    speed = controller.joystick_left()[1]

    # Rotate motor
    motor.go(speed)

[Zoe Foxlin] Ben Carr dropped out? Well yea, I heard that hours ago. I check my DMs.

Make sure your robot has two wheel motors and a weapon motor, like the Purrmenator. Plug the motors in exactly like this.

1

We're short on time, so let's start with the control program you wrote for the Martinez Twins.

We're already using both joysticks, so we'll need to use buttons to control our weapons.

First let's add a line to set up a motor on port C:

Buttons work a little differently than joysticks. Joysticks have a range of motion. We get their position, and then set the motor power to that number, like this.

Buttons don't have a range of motion. They only have two positions. They're either pressed, or they aren't. So the code for buttons is a little different. We need to check if the button is pressed. Here's some code from one of my old control programs where I used the A button to rotate a motor.

This is called an if statement. It's basically like a True/False question. If the answer is True, the code inside it will run.

My code checks if button A is pressed. If so, it sets speed to 100 .

Let's add my if statement to the area where we set motor speed.

When button A is pressed, we should set motor C's speed to 100 . Let's add that line. Give it an extra indent since it's inside the "if statement."

Now add a line to rotate motorC.

Your code should look like this.

Load it onto our robot and away we go!

Um, jk. It's not working. The controller turns off, and the program stops running. Let me ask a chatbot. I'll paste in the full code, and ask:

why isn't this working?

Hurry up hurry up. We've got a battle to get to. Okay, it says:

The variable speedC is inside an if statement, so it's only created if the statement is True.

Oh right! Well there's the problem. We need to make sure the powerC variable is created, even if the button isn't pressed. Let's add a line above our if statement to create powerC no matter what.

Now even if the A button isn't pressed, we're still creating speedC and assigning a value of 0.

Here's the final code.

Load it onto your robot and press the A button to rotate your weapon!

Almost there. You'll be facing some tough competition in this RoboBattle. You might need your weapon motor to rotate backwards. Especially if your weapon is something like a hammer that raises and lowers, or claw that opens and closes.

Let's use the B button for this. Add two lines to our if statement, like this.

elif is like saying, "if the previous True/False question was False, then ask this question."

So if the A button isn't pressed, our code will check if the B button is pressed. If it is, it will set speedC to -100.

Here's the full program.

Take it for a spin!

You know what? This is YOUR creation now. The best robot crafters I know all have their own... signature, I guess? The way they control their robots is as unique as their designs. The "right" way to control your robot is whatever feels right to you.

Go ahead and replace Button.A and Button.B with whatever buttons feel right to you!

  • Main Buttons

    • Button.A

    • Button.B

    • Button.X

    • Button.Y

  • Direction Pad

    • Button.UP

    • Button.DOWN

  • Bumpers

    • Button.LB

    • Button.RB

  • Face Buttons

    • Button.VIEW

    • Button.GUIDE

Or if you want to use the left and right triggers instead, remove the if statements and just set speedC with this one line. The trigger positions range from 0 to 100. This line gets the right trigger position and subtract's the left trigger to give the full speed range from -100 to 100.

2

With these coding skills and a little math, you can make your robot do literally anything. Combine all movement into one joystick. Use a button to activate a turbo boost. Create an ignition or emergency shutoff button. If you can imagine it, you can code it. Come back another time and I'll help you create some really wild stuff. Today, though... no time to spare. The battle is coming right up.

Give your robot some RoboBattles worthy decorations. Remember, recycling points are the key to victory. Decorations should be wild and whimsical, and they should fall apart easily in battle to earn you the most points. Technic™ pieces are usually hard to break apart, so mostly use bricks! Strong chassis, delicate decorations!

If you have a friend or teammate with another robot, challenge them to battle!

3

Rewards

# Set up controller
controller = XboxController()

# Set up motor
motorA = Motor(Port.A)
motorB = Motor(Port.B)

while True:

    # Set motor speed
    speedA = controller.joystick_left()[1]
    speedB = controller.joystick_right()[1]

    # Rotate motor
    motorA.go(speedA * -1)
    motorB.go(speedB)
# Set up motor
motorA = Motor(Port.A)
motorB = Motor(Port.B)
motorC = Motor(Port.C)
speedA = controller.joystick_left()[1]
if Button.A in controller.buttons.pressed():
    speed = 100
    # Set motor power
    speedA = controller.joystick_left()[1]
    speedB = controller.joystick_right()[1]
    if Button.A in controller.buttons.pressed():
    # Set motor power
    speedA = controller.joystick_left()[1]
    speedB = controller.joystick_right()[1]
    if Button.A in controller.buttons.pressed():
        speedC = 100
    # Rotate motor
    motorA.dc(speedA * -1)
    motorB.dc(speedB)
    motorC.dc(speedC)
# Set up controller
controller = XboxController()

# Set up motor
motorA = Motor(Port.A)
motorB = Motor(Port.B)
motorC = Motor(Port.C)

while True:

    # Set motor speed
    speedA = controller.joystick_left()[1]
    speedB = controller.joystick_right()[1]
    if Button.A in controller.buttons.pressed():
        speedC = 100

    # Rotate motor
    motorA.go(speedA * -1)
    motorB.go(speedB)
    motorC.go(speedC)
    speedC = 0
    if Button.A in controller.buttons.pressed():
        speedC = 100
# Set up controller
controller = XboxController()

# Set up motor
motorA = Motor(Port.A)
motorB = Motor(Port.B)
motorC = Motor(Port.C)

while True:

    # Set motor speed
    speedA = controller.joystick_left()[1]
    speedB = controller.joystick_right()[1]
    speedC = 0
    if Button.A in controller.buttons.pressed():
        speedC = 100

    # Rotate motor
    motorA.go(speedA * -1)
    motorB.go(speedB)
    motorC.go(speedC)
    if Button.A in controller.buttons.pressed():
        speedC = 100
    elif Button.B in controller.buttons.pressed():
        speedC = -100
# Set up controller
controller = XboxController()

# Set up motor
motorA = Motor(Port.A)
motorB = Motor(Port.B)
motorC = Motor(Port.C)

while True:

    # Set motor speed
    speedA = controller.joystick_left()[1]
    speedB = controller.joystick_right()[1]
    speedC = 0
    if Button.A in controller.buttons.pressed():
        speedC = 100
    elif Button.B in controller.buttons.pressed():
        speedC = -100

    # Rotate motor
    motorA.go(speedA * -1)
    motorB.go(speedB)
    motorC.go(speedC)
    speedC = controller.triggers()[1] - controller.triggers()[0]

Button.LEFT

  • Button.RIGHT

  • Button.MENU

  • Button.UPLOAD