View Single Post
  #2   Spotlight this post!  
Unread 29-01-2016, 15:09
fovea1959's Avatar
fovea1959 fovea1959 is offline
Herder of programmers
AKA: Doug Wegscheid
FRC #3620 (The Average Joes)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2011
Location: St Joseph
Posts: 327
fovea1959 will become famous soon enough
Re: Joystick Pneumatic Triggering

I think your code will flip the valve back and forth as long as the button is held down. Do you need to detect when the button first goes down, and only execute your logic then?

Untested code:
Code:
// run once
boolean status = false;
boolean buttonWasDown = false;

// run inside operator control loop, or teleopPeriodic, or whatever

boolean buttonIsDown = joystick.getRawButton(3);

if(buttonIsDown && !buttonWasDown)
{
     if(!status)
     {  
           solenoid.kforward();
           status = true;
     }
     else
     {
           solenoid.kreverse();
           status = false;
     }
}
buttonWasDown = buttonIsDown;
Reply With Quote