How do you "lock" a motor with code?

So I made a code that is for my robot. However, when I press a button, the motor spins, yet when I release the button, the motor releases like it has no strength. A friend of mine named Brandon somehow fixed this, but because he made it on his computer, then I can’t get it. I can’t email him either; he’s always busy. So how do I make the motor lock? (with program instructions, please!)

Thanks,
WL

(edit: now the motorgroup doesn’t even have any strength.)

That happened to us. We weren’t able to fix it, but we did find a work around. We decide not to use custom code during driver control and used controller menu to change controls instead.

But it’s not the best solution if you want custom buttons.

simple

if(Controller1.ButtonX.Pressing() == false){
Motor.stop(hold);
}

3 Likes

You can also do motor.setBrake(hold); once, so then every time you do motor.stop();it will hold the position.

https://api.vexcode.cloud/v5/class/classvex_1_1motor?member=classvex_1_1motor_1ae73c540b60bc8196d657b125cdfb2abb

or more descriptive help page for V5 API here:

https://www.robotmesh.com/studio/content/docs/vexv5-python/html/classvex_1_1_brake_type.html


Here’s my code

Using Blocks, explore the ‘Braking’ block and what the 3 different options do.

2 Likes

I fixed it. Thank you for your cooperation!

2 Likes