Quote:
|
Originally Posted by Grizzlie
I am trying to program the solenoids this year to wherewhen i hold the trigger it activates and when i let go it deactivates. Same as the reverse motion. I wrote this code to do this but it wont work. When i press the trigger the solonoid activates but when i let go it doesnt stop. And it WILL NOT go back when i press the rev button. heres the code i wrote :
Code:
if (p3_sw_trig);
{
relay3_fwd = 1;
}
if (!p3_sw_trig);
{
relay3_fwd = 0;
}
if (p3_sw_top);
{
relay3_rev = 1;
}
if (!p3_sw_trig);
{
relay3_rev = 0;
}
It would be great if someone could explain to me what i did wrong here because i'm fairly new to the C language. But it would be even better if someone could post the exact code to make this work. Thank You for even taking your time to read this post. And also good luck this year! 
|
Well, I see three immediate problems. One, all of your if statements end in semicolons. That is bad. Two, your last if statement checks !p3_sw_trig instead of !p3_sw_top. Three, I would suggest using else statements, rather than the structure of if statements that you've chosen. Try this:
Code:
if (p3_sw_trig)
relay3_fwd = 1;
else
relay3_fwd = 0;
if (p3_sw_top)
relay3_rev = 1;
else
relay3_rev = 0;
If you wanted, you could simplify this even further:
Code:
relay3_fwd=p3_sw_trig?1:0;
relay3_rev=p3_sw_top?1:0;
Simpler, though not quite as easy to read.
<edit>
Hm... now that I think about it, you might even be able to do:
Code:
relay3_fwd=p3_sw_trig;
relay3_rev=p3_sw_top;
I don't have an RC with which to test that, but I know the other two methods will work just fine.
</edit>