Here is how I did one button with CommandBased
Use something like (its explained in the OI class):
Code:
ButtonObject.whenPressed(new ToggleSpike());
then inside the command my code:
Code:
private boolean state = false;
private boolean previousState = true;
public SetFeedBelt() {
// Use requires() here to declare subsystem dependencies
// eg. requires(chassis);
requires(feedBelt);
}
// Called just before this Command runs the first time
protected void initialize() {
}
// Called repeatedly when this Command is scheduled to run
protected void execute() {
state = !state;
feedBelt.setBelt(state);
}
// Make this return true when this Command no longer needs to run execute()
protected boolean isFinished() {
if(state != previousState) {
return true;
} else {
return false;
}
}
// Called once after isFinished returns true
protected void end() {
previousState = state;
}
So with two buttons make it two button.whenPressed(new onOrOffCommand()); and two commands, and if they require the spike subsystem it will handle the interrupts for you.