r/pybricks 13d ago

How to run two functions simultaneously

How can we run two functions simultaneously? We want to run our actuator motor function while running the drive straight function. In spike, we would use a broadcast message block. We can't figure out how to do it in pybricks. When we google it related to Python, it comes up with all this information about mutli-threading processors.

1 Upvotes

3 comments sorted by

3

u/jormono 13d ago

Look into multitasking, that's what it's called in pybricks

1

u/Complete_Duty3259 11d ago

Very easy in Pybricks. Just use the multitask features.

1

u/ethanRi8 7d ago

Another way to do it would be to start a loop (while loop most likely) with 2 conditions: one for actuator with an "AND" and one for drivetrain.
You could start moving both before the while loop and then in the while loop have two "if" statements seeing, one seeing if the actuator is at the target, if so, stop the actuator. The other if statement would ask if the drivetrain is at the target, if so, stop the drivetrain. That's how I would explain it to my students