Quote:
Originally Posted by dpick1055
It's actually fairly simple to have the trigger control an action with the pneumatics. What have you to do is declare some variable like handstate.
Then when your trigger is pressed changed the value of handstate to 1 or 0. Then when the trigger is pressed you know whether your hand is opened or closed and you can do an action based on it.
Code:
int handstate;
handstate = 0; //default position for whatever your using
if (p1_sw_trig == 1 && handstate == 0)
{
relay2_fwd = 1;
handstate = 1;
}
if (p1_sw_trig == 1 && handstate == 1)
{
relay2_rev = 1;
handstate = 0;
}
|
Wouldn't that code just rapidly switch between forward and reverse relays? The handstate would immediately change to 1 when the trigger is pressed, so the next
if statement will be true and the relay will be set to reverse. You need to check when the trigger is depressed. Something like:
Code:
int handstate;
handstate = 0; //default position for whatever your using
if (p1_sw_trig == 1 && handstate == 0)
{
relay2_fwd = 1;
handstate = 1;
}
if (p1_sw_trig == 0 && handstate == 1)
{
handstate = 2;
}
if (p1_sw_trig == 1 && handstate == 2)
{
relay2_fwd = 1;
handstate = 3;
}
if (p1_sw_trig == 0 && handstate == 3)
{
handstate = 0;
}
I think. Please correct me if I am wrong.