Quote:
|
Originally Posted by willie837
...pneumatic arm with three different cylinders...one joystick...three different buttons to operate each cylinder, the first press to activate the cylinder out, and the second press of the same button to retract it.
|
Fortunately, the white joysticks have lots of buttons! Assuming the joystick is on Port 4 of the OI, the trigger is
p4_sw_trig, the thumb button is
p4_sw_top, the left hand button on top is
p4_sw_aux1, and the right hand button on top is
p4_sw_aux2. Pick which three you want to use. I'll show you how to use the trigger for what you want, assuming you're using a double solenoid connected to a Spike on Relay 1, and you can go from there.
In the
Default_Routine() function in
user_routines.c, use this code:
Code:
static char last_trig = 0; // this is what the switch state was last time
static char cylinder_state = 0; // this is what we last told the cylinder
if (last_trig == 0 && p4_sw_trig == 1) // the switch was just now pressed
{
if (cylinder_state == 0) // the cylinder was retracted, need to extend
{
cylinder_state = 1; // remember that we're extending it
relay1_fwd = 1; // do whatever it takes to activate the solenoid
relay1_rev = 0;
}
else // the cylinder was extended, need to retract
{
cylinder_state = 0; // remember that we're retracting it
relay1_fwd = 0; // do whatever it takes to reverse the solenoid
relay1_rev = 1;
}
}
last_trig = p4_sw_trig;