Quote:
|
Originally Posted by Mark McLeod
...and there should be no colon (or semicolon) after "254". It really should be:
Code:
if (rc_dig_in06 == 0)
pwm01=254
else
pwm01=127;
or if you really like to run things together:
if (rc_dig_in06 == 0) pwm01=254 else pwm01=127;
|
umm... no. There
should be a semicolon after the 254 - it is the end of an instruction. the correct format is this:
Code:
if(rc_dig_in06 == 0)
pwm01 = 254;
else
pwm01=127;
(you can always rearrange that however you wish with tabs, spaces, and line breaks)
Remember, the if-else statement is a control structure, and thus does not count as part of a single instruction. The two instructions here are "pwm01 = 254" and "pwm01 = 127", each of which needs to be ended with a semicolon as shown.
You may have been confused with the colon because of the if-else shorthand notation - for instance, the code below does the exact same thing as the longer if-else below:
Code:
pwm01 = ( rc_dig_in06 ? 127 : 254 );
if you are new to programming, though, stick with the longer if-else statement, as it is easier to read and use.