View Single Post
  #13   Spotlight this post!  
Unread 14-06-2006, 23:14
foobert foobert is offline
Registered User
no team
 
Join Date: May 2005
Location: oakland, ca
Posts: 87
foobert is a jewel in the roughfoobert is a jewel in the roughfoobert is a jewel in the rough
Re: VEX Start Kit Projects

Quote:
Originally Posted by artdutra04
(Remember, the part of C programming that makes this all possible is that any conditional statement inside parenthesis will return a 1 if true, and a 0 if not. So using the assignment left_drive = 127-42(ultrasonic_value>40); will return either 127 if the ultrasonic sensor value is less than 40, or it will return an 85 if the ultrasonic value is greater than 40. It is these conditionals inside an assigment that makes the three-lines of code possible.)
this is not a good idea. since multiplication is kind of expensive, computationally speaking go with...

Code:
left_drive = (ultrasonic_value > 40) ? 85 : 127;
... which, for anyone unfamiliar with the notation, is pretty much the same as ...

Code:
if (ultrasonic_value > 40) left_drive = 85;
else left_drive = 127;
Reply With Quote