Hey there everyone, I’m trying to re-code my drive code from a while loop, into an If/Else Statement. The reason why I’m doing this is so the motors can break upon releasing the joystick. But that can only be done in an If/Else Statment.
Bellow is my current Code:
vex::motor_group left(Front_Left, Back_Left);
vex::motor_group right(Front_Right, Back_Right);
vex::drivetrain dt(left, right, 335, 380, 330, mm);
while (1) {
left.spin(directionType::fwd, Controller1.Axis3.value(), velocityUnits::pct);
right.spin(directionType::fwd, Controller1.Axis2.value(), velocityUnits::pct);
It works wonderfully, but again it’s a while loop not an If/Else Statement
This is what I currently have, but it doesn’t work:
vex::motor_group left(Front_Left, Back_Left);
vex::motor_group right(Front_Right, Back_Right);
vex::drivetrain dt(left, right, 335, 380, 330, mm);
int ChassisSpeedRPM = 200;
if(Controller1.Axis2.()) {
left.spin(directionType::fwd, ChassisSpeedRPM, velocityUnits::pct);
} else if(Controller1.Axis2.()) {
right.spin(directionType::rev, ChassisSpeedRPM, velocityUnits::pct);
} else {
drivetrain.stop(brakeType::break);
}
If anyone knows how to code drivecode in an If/Else statement please let me know. I’m really struggling. Thank you in advance for any support those may be able to give. Thanks for reading and have a great day.