View Single Post
  #10   Spotlight this post!  
Unread 29-10-2014, 14:16
Secretspy97 Secretspy97 is offline
Registered User
FRC #1126
Team Role: Programmer
 
Join Date: Oct 2011
Rookie Year: 2009
Location: New York
Posts: 25
Secretspy97 is an unknown quantity at this point
Re: Need a Code for Solenoid to Shift

The code below allows a joystick on port 1, to extend/retract a solenoid on port 1 by pushing button 1. It also adds a simple debump statement which makes the solenoid change state only when the button is first press.

<CODE>

//Instance Variables
public Solenoid shifter;
public Joystick joy;

//IN CONSTRUCTOR
shifter = new Solenoid(1);//1 is the port number
joy = new Joystick(1);


//IN TELEOP METHOD
boolean firstPress = true;
boolean inHighGear = false;

while(true){
if(joy.getRawButton(1) && firstPress){//first button
inHighGear = !inHighGear;
firstPress = false;
}else if(!joy.getRawButton(1)){
firstPress = true;
}
shifter.set(inHighGear);
}

</CODE>

Hope this helps!!
__________________
WHAT TIME IS IT?
1126