Toggle Speed adjustment Help

I’m just tank drive with a Xbox controller, i want to make it so when i press one of the two triggers it will make a limit the speed of the robot.

My code :

#include “WPILib.h”

class DemoRobot : public SimpleRobot
{
RobotDrive drivetrain;
Joystick xbox;
public:
DemoRobot() :
drivetrain(1, 2), xbox(1)
{
GetWatchdog().SetEnabled(false);
}

void Autonomous() {}

void OperatorControl()
{
while (IsOperatorControl()) {
drivetrain.TankDrive(xbox.GetY(), xbox.GetRawAxis(5));
Wait(0.005);
}
}
};

START_ROBOT_CLASS(DemoRobot);

I’m not familiar with C++, but in general, one can simply multiply the joystick values by a constant, if the button is pressed, before feeding it to the drive.

Read the raw joystick values into temporary variables. If the button is pressed, multiply the values by something less than one. Feed those variables into the TankDrive function.