|
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
|