Dance Video
Last updated
Last updated
🏆 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 BOT. 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 bot is RIPPING circles around it. WHAT.
Chat goes nuts. The clip blows up. My followers DOUBLE. Everyone's DM'ing me about this bot.
The algorithm's begging for more sinkhole bot. Gotta get more content out of it. So I got this idea.
DANCE VIDEO.
Picture this. We drop a track. Your bot 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 bot 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 bot can spin with the beat. The dance has gotta be perfect.
[Zoe Foxlin] Bot code? For a dance video!? With Stewskee!?! Omg yes. I'm fangirling right now.
Just like last time, make sure you've got a bot with wheel motors, like the Purrmenator. The left motor has to be plugged into port A.
Let's start with the old code we found online for the sinkhole bot.
We turned this into a mean patrolling machine by changing its motor direction and power. But for a dance video, you don't need a self-driving bot. You need a bot 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 power
number. What's actually going on when we do that? Let's look at the line.
power
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 power
.
🤔 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 power
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 power
value for the rotation power.
Any time we write the variable power
, the computer uses the value stored inside it. We know that power
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 power
variable.
We want our Xbox joystick to control the rotation power. So instead of storing 20
or 100
or whatever in the power
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 bots. 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 power
, 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 power?
It said:
power
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 power
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.
Don't worry about these lines. They add modules. Basically premade code that lets our program work. Just be sure to paste them at the start of every bot program you make.
Next line. 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?
Blast your favorite beats.
Turn on your bot and connect your controller.
Drop that signature SPIN. Move the joystick up and down to step back and forth with the beat.
Got a phone? Shoot it, or ask a buddy.
If you've got permission, POST THIS THING. #BotBattles
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.