I need help on programming a motor

I need help coding a motor to only move in a certain range so that it can’t move past forward past 95-ish degrees and backward past 330ish degrees. I have looked everywhere I could think to. I just can’t figure it out. Nobody that I know knows. Help would be greatly appreciated. Also I’m using block code on vexcode v5

Could you put limit or button switches at the two extremes and not allow the motor to drive in that direction when the switch is engaged?

It sounds like the spinTo function would accomplish this

If not perhaps you could only spin the motor if it is in the desired range determined by the value of the encoder in the motor

Excuse me, I want to ask for help. Can I set a program that control the base of robot move fast and slow ?
for example, when I start the robot that using 80 percent, press one button that change to 50 percent.
Can I do that ? I can’t set this program, can anyone help me, thanks a lot.

image

yes with this:Screenshot 2021-09-27 10.16.24 AM

I am using vexcode v5 text

Sorry, this is about IQ or VRC ? thx

its v5 i cant post this without more characters

the pseudo code logic for the OP question is:

if (motorPosition > 95){ button makes motor go forward code }
else if (motorPosition < 330){ button makes motor go backward code }
else { motor stop }

can you put in block code?

Please work through the logic with the options available to you in your block code interface of choice.
In block code, the evaluation of the if statement is what I show (inside parenthesis) the action to take when the if evaluation is true is shown {in curly brackets}

1 Like

We actually have something similar to this on our bot; I call it a slow button cause it just makes our drive script move a little slower, but you could use it for anything.

I have it set up where you have two callback functions (you could probably do this with one and a sender type thing but this worked fine for my application). I had it set up similar to this:

Controller1.ButtonA.pressed(slowButton);
Controller1.ButtonB.pressed(fastButton);

Again, probably not best practice, but inside these functions I have it change a global variable, which I use as a multiplier, but you can do it however you want. Good luck!

Edit: For your case you could probably do a motor.setVelocity