I have a great code that spins a different speed while holding down an additional button L2 so that the joysticks and buttons all spin slower when L2 is pressed.
while(1) {
int x;
int jstick = 3;
int greenFullSpeed = 190;
int redFullSpeed = 90;
int greenHalfSpeed = 90;
int redHalfSpeed = 40;
// set speed conditions
if (Controller1.ButtonL2.pressing()) {
x = greenHalfSpeed;
jstick = 3;
}
else {
x = greenFullSpeed;
jstick = 1;
}
LeftFrontMotor.spin(directionType::fwd,
(Controller1.Axis3.value() / jstick),
velocityUnits::rpm);
LeftRearMotor.spin(directionType::fwd, (Controller1.Axis3.value() / jstick),
velocityUnits::rpm);
RightFrontMotor.spin(directionType::fwd,
(Controller1.Axis2.value() / jstick),
velocityUnits::rpm);
RightRearMotor.spin(directionType::fwd,
(Controller1.Axis2.value() / jstick),
velocityUnits::rpm);
// Controller forward
if (Controller1.ButtonR1.pressing()) {
LeftFrontMotor.spin(directionType::fwd, x, velocityUnits::rpm);
LeftRearMotor.spin(directionType::fwd, x, velocityUnits::rpm);
RightFrontMotor.spin(directionType::fwd, x, velocityUnits::rpm);
RightRearMotor.spin(directionType::fwd, x, velocityUnits::rpm);
}
//controller reverse
if (Controller1.ButtonR2.pressing()) {
LeftFrontMotor.spin(directionType::rev, x, velocityUnits::rpm);
LeftRearMotor.spin(directionType::rev, x, velocityUnits::rpm);
RightFrontMotor.spin(directionType::rev, x, velocityUnits::rpm);
RightRearMotor.spin(directionType::rev, x, velocityUnits::rpm);
}
}
it is all one code but I split it up so it is easier to read