If you want it to toggle, (untested)
Code:
bool hasJoystickBeenClicked(Joystick &joystick, bool &prev, bool &cur) {
prev = cur;
cur = joystick.GetTrigger();
// Previous joystick value should be true (pressed trigger) and
// current one should be false (released trigger).
return (prev && !cur) ? true : false;
}
void getMotorSpeed(float &speed, bool half) {
return (half) ? speed / 2 : speed;
}
void toggleHalfSpeed(bool &half) {
half = !half;
}
// ...
if (hasJoystickBeenClicked(joystick, prev, cur))
toggleHalfSpeed(isHalfSpeed);
// ...
motor.Set(getMotorSpeed(speed, isHalfSpeed));
EDIT: More code.