View Single Post
  #5   Spotlight this post!  
Unread 15-02-2012, 10:50
gixxy's Avatar
gixxy gixxy is offline
Programming and Arduino Mentor
AKA: Gustave Michel III
FRC #3946 (Tiger Robotics)
Team Role: Mentor
 
Join Date: Nov 2011
Rookie Year: 2012
Location: Ruston, LA
Posts: 207
gixxy is on a distinguished road
Re: Relay Button Issue

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.

Last edited by gixxy : 15-02-2012 at 10:55. Reason: Forgot info
Reply With Quote