What you have to do in the code is put in an if statement that will switch between the 2 positions on the pneumatics, but since the loop executes every 26ms(approx.) you'll also need to include a latch to prevent this.
The following code is similar to what my team did for this:
Code:
if(p1_sw_top == 1 && button_latch==0) //button_latch is a variable to
// prevent the code from rapidly cycling through piston positions
{
if(relay1_rev==1)//if the relay is reversed it will switch to forward
{
relay1_fwd=1;
relay1_rev=0;
button_latch=1;
}
else //and vice versa
{
relay1_fwd=0;
relay1_rev=1;
button_latch=1;//latches to prevent cycling
}
}
else if(p1_sw_top == 0 && button_latch==1)
{
button_latch=0;//resets latch when you let go of the button
}