View Full Version : Need a Code for Solenoid to Shift
Hi, I'm a new programmer. I've been assigned the task to make a solenoid shift when a button is pushed (such as buttons 4 and 5 on a joystick [tank drive]).
If anyone has a fully functional code that allows a solenoid to shift with a push of a button, please reply with it here. It would be very helpful and I'd really appreciate it.
Thank you! :)
Language as in, does your team use C++, Java, LabVIEW?
English.
Sorry, what programming language? Java, C++, or LabView.
English.
What happened to the last person to answer that question that way:
http://www.chiefdelphi.com/forums/showthread.php?postid=907118#post907118
And it includes a Labview example.
Thanks for clarifying. I didn't know, haha.
Assuming you have a double-acting solenoid, you want to use the DoubleSolenoid class (http://robotics.francisparker.org/javadoc/edu/wpi/first/wpilibj/DoubleSolenoid.html). DoubleSolenoid.set() is the method that shifts the solenoid.
Secretspy97
29-10-2014, 14:16
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!!
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.