When you have two mutually exclusive tests like that, you can use the
if statement's
else clause.
Code:
if (rc_dig_in06 == 1)
{
pwm01 = (long) Get_Analog_Value(rc_ana_in01) * 127 / 1023 + 127;
}
else
{
pwm01 = (long) Get_Analog_Value(rc_ana_in01) * -127 / 1023 + 127;
}
Note that I've removed the parentheses around (127/1023). With them in place, the intermediate result of the division will be zero, and I believe you'll find the output never varies from 127. Instead, you want to defer the division until as late as possible so you don't lose bits that you need.
I'd actually have done it a little differently:
Code:
pwm01 = (int)127 + Get_Analog_Value(rc_ana_in01) * rc_dig_in06?127:-127 / 1023;
But that's probably more cryptic than it needs to be for your purposes.