How can I make two things go at once?

So I’m really bad at this and I just started using python (I used to use blocks) and I’m really dumb. How do I code two motors to move at once? say it was named motor_1 and motor_2 and I need both to spin forward at the same time. How exactly would I code that? Thanks!

Do you want it to just spin endlessly? (Until you tell it to stop) If so, use the top

Do you want it to spin a certain amount of degrees? If so, use the bottom.

I hope this is what you’re looking for!

does this make them spin at the same time? I thought this would make one spin and then the other spin

Try it and see.

The python commands will be very similar to the block commands.

3 Likes

My fault, I thought you were running blocks. Yes, as long as you set wait = false for the spin_for function, it will run them essentially at the same time. The spin function will not wait.

and follow-up question, I’m trying to make it so that when I press my touchLED (touchled_9) it begins my code. can anyone take a look at it and tell me what stands out? Thank you!
image

And I forgot to mention in the previous post, right now nothing happens when I press the touchLED. It turns red-violet but it doesn’t play the code when I press it

First you create a function that will perform the actions when the button is pressed

def MyRobotMoves():
    Intake_1.spin(FORWARD)
    drivetrain.drive_for(FORWARD, 38, INCHES)
...

Then you bind a button pressed event (Event Handlers are a very useful in programming):

# event handlers
touchled_9.pressed(MyRobotMoves)
# add 15ms delay to make sure events are registered correctly.
wait(15, MSEC)
...

1 Like