# Dance Video

<figure><img src="/files/OcETqdxR1iUgNgxvuNzq" alt=""><figcaption></figcaption></figure>

### Rewards

* :trophy: **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.

## Best Recycler Takes It

**\[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 [Purrmenator](/tutorial/your-first-robot.md). The left motor has to be plugged into port A.

<figure><img src="/files/XP2OMm0JkaTlHjGn2C3G" alt="" width="563"><figcaption></figcaption></figure>

<figure><img src="/files/cr4uiaxfgkU9CKKwdhC2" alt=""><figcaption><p>1</p></figcaption></figure>

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

```python
# Set up controller
controller = XboxController()

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

# Set motor speed
speed = 20

while True:

    # Rotate motor
    motor.go(speed)
```

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.

## Variables

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.

```python
speed = 20
```

* `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`.

:thinking: 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.

```python
# Set up controller
controller = XboxController()

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

# Set motor speed
speed = 20

while True:

    # Rotate motor
    motor.go(speed)
```

<figure><img src="/files/cr4uiaxfgkU9CKKwdhC2" alt=""><figcaption><p>2</p></figcaption></figure>

There it is, right at the end.

```python
    # Rotate motor
    motor.go(speed)
```

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...

```python
    motor.go(speed)
```

... the computer basically does

```python
    motor.go(20)
```

## Objects

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.

```python
# Set up controller
controller = XboxController()

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

# Set motor speed
speed = 20

while True:

    # Rotate motor
    motor.go(speed)
```

<figure><img src="/files/cr4uiaxfgkU9CKKwdhC2" alt=""><figcaption><p>3</p></figcaption></figure>

There it is.

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

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.

## Xbox Joystick

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.

```python
# Set up controller
controller = XboxController()
```

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.&#x20;

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

```python
# Get joystick's vertical position
controller.joystick_left()[1]
```

Good thing I left a comment. Thanks, old me. :handshake: So this code will get the joystick's vertical (up/down) position from our `controller`.&#x20;

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

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

The final code should look like this.

```python
# 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)
```

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

<figure><img src="/files/cr4uiaxfgkU9CKKwdhC2" alt=""><figcaption><p>4</p></figcaption></figure>

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

## While Loop

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:&#x20;

> 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. :palm\_down\_hand::dog: Take a look at these lines at the end of the program.

```python
while True:

    # Rotate motor
    motor.go(speed)
```

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.

```python
while True:

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

    # Rotate motor
    motor.go(speed)
```

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

The full program should look like this.

```python
# 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)
```

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

<figure><img src="/files/cr4uiaxfgkU9CKKwdhC2" alt=""><figcaption><p>5</p></figcaption></figure>

## From the Top

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.

```python
# Set up controller
controller = XboxController()
```

We know this. What does it do?

<figure><img src="/files/cr4uiaxfgkU9CKKwdhC2" alt=""><figcaption><p>6</p></figcaption></figure>

Next! What does this do?

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

<figure><img src="/files/cr4uiaxfgkU9CKKwdhC2" alt=""><figcaption><p>7</p></figcaption></figure>

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

```python
while True:

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

    # Rotate motor
    motor.go(speed)
```

<figure><img src="/files/cr4uiaxfgkU9CKKwdhC2" alt=""><figcaption><p>8</p></figcaption></figure>

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.

## Make it Pop

**\[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.

<figure><img src="/files/cr4uiaxfgkU9CKKwdhC2" alt=""><figcaption><p>9</p></figcaption></figure>

## Fire

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.
5. If you've got permission, POST THIS THING. #BotBattles

<figure><img src="/files/cr4uiaxfgkU9CKKwdhC2" alt=""><figcaption><p>10</p></figcaption></figure>

## Legend

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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://play.robobattles.com/adventure/quests/dance-video.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
