Looks like you need to put the conveyor code within the operatorControl method.
Also you need to use the joystick method getRawButton() in order to get the state of a button.
The updated code below should work better.
Code:
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.RobotDrive.MotorType;
import edu.wpi.first.wpilibj.SampleRobot;
import edu.wpi.first.wpilibj.Timer;
/**
* This is a demo program showing how to use Mecanum control with the RobotDrive class.
*/
public class Buttontest extends SampleRobot {
RobotDrive robotDrive;
Joystick stick;
// Channels for the wheels
final int frontLeftChannel = 0;
final int rearLeftChannel = 1;
final int frontRightChannel = 2;
final int rearRightChannel = 3;
// The channel on the driver station that the joystick is connected to
final int joystickChannel = 3;
private Object conveyorMotor;
private Object joystick;
private Object set;
public Buttontest() {
robotDrive = new RobotDrive(frontLeftChannel, rearLeftChannel, frontRightChannel, rearRightChannel);
robotDrive.setExpiration(0.1);
stick = new Joystick(joystickChannel);
}
/**
* Runs the motors with Mecanum drive.
*/
public void operatorControl() {
robotDrive.setSafetyEnabled(true);
while (isOperatorControl() && isEnabled()) {
// Use the joystick X axis for lateral movement, Y axis for forward movement, and Z axis for rotation.
// This sample does not use field-oriented drive, so the gyro input is set to zero.
robotDrive.arcadeDrive(-stick.getY(), -stick.getX());
if (stick.getRawButton(3)) {//if button 3 is pressed go full speed up
conveyorMotor.set(1);
}
else if (stick.getRawButton(4)) {//button 4, full speed down
conveyorMotor.set(-1);
}
else{
conveyorMotor.set(0); //no button pressed, stop
}
Timer.delay(0.005); // wait 5ms to avoid hogging CPU cycles
}
}
}