Question about Dbl Acting Pneumatics program

So I have programmed our pneumatics with the help of the sample program. However I have noticed that with this program, when you activate the pneumatics, you have to hold the button in until you want to close them again. I was wondering if there is a possibility of you pressing the button, then taking your finger off of it and then press it again to close them again?

Thanks

I prefer to hold the previous state of the button each round. Since you haven’t specified what language, I’m going to roll with ROBOTC, but I don’t have it installed. The only difference between this code and any other language will be how you call the button state (vexRT[Btn5U]) and how you activate the solenoid (SensorValue[solenoid]). Take a look at the following code, and then I’ll try to explain in human-terms:

bool Btn5UWasPressed = false;

while(true)
{
	if(!Btn5UWasPressed && vexRT[Btn5U]) // Button was not pressed during last check AND button is currently pressed
	{
		// Logic to switch solenoid values. There are more simplistic ways, but this is probably easiest to comprehend
		if(SensorValue[solenoid] == 1)
			SensorValue[solenoid] = 0;
		else
			SensorValue[solenoid] = 1;
	}
	Btn5UWasPressed = vexRT[Btn5U]; // Update "WasPressed" for next loop
	// More operator control code	
}

The basic premise behind this snippet is that each time you run through your while loop, you check to see if the button has changed from the previous run. If the button becomes pressed, but it wasn’t previously, we know that the press is a new press and, therefore, we can change the solenoid state. That’s what if(!Btn5UWasPressed && vexRT[Btn5U]) determines. The code that runs inside the if condition checks what the solenoid state currently is and changes it appropriately. I would normally use something a little but shorter like a ternary or a boolean operation (see below), but this gets the point across. The final statement, Btn5UWasPressed = vexRT[Btn5U]; updates the “WasPressed” Boolean so next time the loop runs, we’ll know what the true last value was.
It’s also important to note that the button initializes with a value of false, since we didn’t know what the value was previously (because we haven’t run anything).

Hope this helps, and let me know if it doesn’t compile correctly - it’s been a while since I’ve worked with ROBOTC and I changed up my usual logic to be more efficient and simpler. EDIT: I was able to compile. It looks like there’s a warning for converting vexRT] to a boolean. I think it’ll work fine but if not, use: Btn5UWasPressed = (vexRT[Btn5U] == 1 ? true : false);

// boolean operator (may not work in ROBOTC, can't remember)
SensorValue[solenoid] = !SensorValue[solenoid];
// Ternary operator
SensorValue[solenoid] = (SensorValue[solenoid] == 0 : 1 : 0);

I am using easy C :smiley:

Could you post the code in easyC?

Thanks

In EasyC v4, you’ll want to use the Joystick to Digital Latch block, which will get the same functionality as what I posted. Use it just like any other Joystick function.

OK, and I would I use this instead of the digital output button?

Yes. You’ll just need to use Joystick to Digital Latch. You will not need to use Joystick to Digital or Digital Output in this case.

The code still isn’t working…
gfsdfgfdgd.JPG

EasyC implements the functionality behind JoystickToDigitalLatch of the example code I original posted, so you won’t need any of what I originally wrote.

while(1)
{
	JoystickToDigitalLatch(1,8,1,12);
}

You won’t need any of the other JoystickToDigitalLatch functions or if/elseif structure that you have.

If you’re still having issues, I can pull up EasyC when I get home tonight and give you a screenshot.

I think I kind of understand, however if you could show me on easyC when you get home, that would be great !

https://6k5fxq.bn1302.livefilestore.com/y2puxDPWfdLJwAiVMYwDmbwPhbjOMqYlZPNOlee-VhdswPACj5R68jJPPwvQfEGQqaxVGMYzVMlAYM3VeM-i3EexN_z3kbiDNYrQpTUAfnoNYo/VoltRobotics-DigitalLatch.png

Hope this helps!

ninjaedit: I can’t spell “chassis”