View Single Post
  #3   Spotlight this post!  
Unread 21-04-2004, 07:35
Astronouth7303's Avatar
Astronouth7303 Astronouth7303 is offline
Why did I come back?
AKA: Jamie Bliss
FRC #4967 (That ONE Team)
Team Role: Mentor
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Grand Rapids, MI
Posts: 2,071
Astronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud of
Re: Limit Switches help.

Quote:
Originally Posted by MikeDubreuil
It's important to remember that in C "==" is a logical equal to operator and "=" is an assignment operator. "<=" is also a logical operator meaning less than or equal to. So I think you would want your code to look like this:

Code:
if (rc_dig_01 == 1) {
     if (joy_1 <= 127) {
          joy_1 = joy_1;
     } else {
          joy_1 = 127;
     }
} else {
     joy_1 = joy_1;
}
A good place for ternaries!

Full code might look like this:
Code:
if (RC_LIMITDOWN) //Alias to digital in
 Joy_1 = ((Joy_1 < 127) ? 127 : Joy_1)
else if (RC_LIMITUP)
 Joy_1 = ((Joy_1 > 127) ? 127 : Joy_1)