View Single Post
  #3   Spotlight this post!  
Unread 12-02-2012, 21:25
NS_Radication's Avatar
NS_Radication NS_Radication is offline
Student
AKA: Marco Schoener
FRC #1369 (Minotaur)
Team Role: Programmer
 
Join Date: Jan 2012
Rookie Year: 2009
Location: Tampa
Posts: 88
NS_Radication is an unknown quantity at this point
Re: Relay Button Issue

Well, I coded an on/off switch recently and I came up with a one button toggle after a two button toggle.
Code:
public void teleopPeriodic()
{
    boolean spikeToggle = false;
    spike.set(Relay.Value.kOff);
    if(joy1.getRawButton(BUTTON_NUM)) //set the button to activate motor for the joystick
    {
        if(spikeToggle == false) // if the toggle is off, set to true and activate motor
        {
            spikeToggle = true;
            spike.set(Relay.Value.kOn);
        }
        Timer.delay(0.5); // cannot change the value within the first half second of activating, you can change value but it is here to have a safe toggle without toggling every millisecond
        else if(spikeToggle == true) // if the motor is on, turn it off and it is set to false
        {
            spikeToggle = false;
            spike.set(Relay.Value.kOff);
        }
        Timer.delay(0.5); // again it stalls the change for convenience and safety
    }
}
Two buttons were crazy, but if you want two buttons, just replace the else if with the if statement and add it to the second button loop. Hope this helped.

If you have any questions and comments, just reply or post, etc.

Happy Competitions!
__________________
Team 1369
Senior
Head Programmer (Java)
Head Electrician
Reply With Quote