Code:
public void teleopPeriodic() {
if (stick.getRawButton(1) && !limitSwitch ) {
motor1.set(0.5);
}
else if (stick.getRawButton(2)) {
motor1.set(-0.5);
}
else {
motor1.set(0.0);
}
}
do you have two limit switches, or just one? Which way is it supposed to prevent motion?
The key changes i made here are using boolean logic to modify the if statement, and to chain both statements together using else if.
I'd also suggest formatting your code in a nested fashion. It's really useful when debugging
Lastly, i am a proponent of making sure all your logic only has one way to set the motor, so I move all my Motor Set commands to the very end, and use a variable to keep track of what i want the motor to do. This is also helpful for displaying the desired command on smartdashboard for debugging. Similarly, gather all your inputs at the begining to meaningful variable names as well
Code:
public void teleopPeriodic() {
boolean intakeMotorForward = stick.getRawButton(1);
boolean intakeMotorBackward = stick.getRawButton(2);
if (intakeMotorForward && !limitSwitch ) {
intakeMotorSpeed = 0.5;
}
else if (intakeMotorBackward) {
intakeMotorSpeed = -0.5;
}
else {
intakeMotorSpeed = 0;
}
motor1.set(intakeMotorSpeed);
}