Single solenoid code for frc robot in java language. Solenoid works when 5 key is pressed, solenoid turns off when 6 key is pressed. Can you help me to write a code with CTRE control module, using 2 solenoids, one to open and the other to close?
Can you share your code?
Should be very similar to what you currently have.
this is my single solenoid code
this is my double solenoid code
I want to write a single solenoid code with the same logic. By using 2 solenoids, one to open and the other to close.
What is the problem with the single solenoid code? It looks like it should work to me based on the description of what you want it to do.
Make sure that you aren’t writing to it anywhere else.
no problem. the problem solved thank you
ı have one problem. I cannot adapt the else part of the double solenoid to a single solenoid
I cannot adapt the else part of the double solenoid to a single solenoid
You’ve fixed uour problem, so I there was a code change. Please share your current code so we know what you changed.
A single Solenoid only has two states: true or false.
Your logic is looking for three states with if/else if/else. What do you want your code logically to do?
If button 5 is pressed, turn it on, if button 6 is pressed, turn it off. If nothing is pressed, leave it alone?
boolean _set_value = m_solenoid.get();
if(controller.button5()){
_set_value = true;
} else if (controller.button6()){
_set_value = false;
} else {
// leave it alone
}
m_solenoid.set(_set_value);