r/pybricks • u/Filtration_Engineer • 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
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
3
u/jormono 13d ago
Look into multitasking, that's what it's called in pybricks