Chainging Speed on motors VexCode

I am trying to make my robot speed up and slow down by pushing a button on the controller (ButtonX). I want it where pushing it once speeds it up to normal speed, then pushing it again causes it to slow down to half speed. This is what I have so far, but I am lost how to get continue the code. I am using VexCode Text with the new V5 smart motors.

FrontLeftDriveMotor.spin(vex::directionType::fwd, Controller1.Axis3.position(), vex::velocityUnits::pct);
BackLeftDriveMotor.spin(vex::directionType::fwd, Controller1.Axis3.position(), vex::velocityUnits::pct);
FrontRightDriveMotor.spin(vex::directionType::fwd, Controller1.Axis2.position(), vex::velocityUnits::pct);
BackRightDriveMotor.spin(vex::directionType::fwd, Controller1.Axis2.position(), vex::velocityUnits::pct);

You can use the if command for this. However, I don’t know how to make pressed work instead of pressing. I know it has something to do with callbacks, but I don’t know where to even begin with that.

I also can not figure out how to change drive speed, I can change the speed of the claw and other parts of my robot, but not the drive speed. If you have any way to slow down the speed that would also be helpful. I can not find any resources online that tell me how to do it. This is the code I used to change the speed of the arm, but I can not put in the speed because I need the variable for the controller for the wheels:

  ArmMotor.spin(vex::directionType::fwd, armSpeedPCT, vex::velocityUnits::pct);

I identified what armSpeedPCT meant earlier in the code:

int armSpeedPCT  = 50;

I am overall just trying to slow down the wheels.

For the slow mode, i’d recommend you start out with a more simple solution. You can do an if statement like this:

    if(controller.button.pressing) {
    drivemotors.spin(fwd, joystick value * 0.5, pct)
    else {
    drivemotors.spin(fwd, joystick value, pct)

This code will make the robot move at half speed when a button is pressed down, and it will move at full speed when it is not.
You can change the speed of the drive by updating a variable, equal to the axis of the joystick.

You just need to create another variable. I’d suggest looking at some more examples from vex, as I get the impression you’re new to C.

I am using VexCode, I am not using C

C++ is the programming language you use in vexcode.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.