My group just started programming our robot and need a way to program a motor not to spin clockwise when a sensor is pressed. We are new to vex, so how would you do it? We are using EasyC 2.0.

It depends on the sensor output. Lets assume its a bumper switch. I believe ouput for a bumper sensor is 1, when pressed.

when (bumperOutput == 1)
//set pwm motor to 127

the one thing is would that let us turn counter clockwise?

to turn counter clockwise, just set pwm to 0 or 254. I forgot which it was, but its easy to find out by experimentation.

i am talking about rc control

not autonomous.

Hey, you are just trying to code up a limit switch - to stop rotation in one direction when a switch is closed, but not limit its motion at all in the other direction.

If you take the default user code and modify it so that when the bumper switch is down, you “clamp” the range of whichever motor port you are limiting, you’ll get the effect you are looking for.

If you download the Vex Starter Code from here, and look in the file “user_routines.c”, you’ll see two functions Limit_Switch_Max() and Limit_Switch_Min() that do what you want. You call them from your main loop, passing in the switch value and the address of the pwm value you want to limit. Something like this:

Limit_Switch_Max(rc_dig_in01, &pwm01);
// or, depending on direction...
Limit_Switch_Min(rc_dig_in01, &pwm01);

If you look at page 5.9 in the Inventor’s Guide, you’ll see that the default behavior of the Vex Micro Controller is to use Digital Ports 1-8 as limit switch inputs for Motor ports 4-7.

  • Dean

thanks for the help