anonymous
  • anonymous
Hello, I've encountered some C code interfacing with the distance sensor, but i find some parts of the code abit confusing. any1 can explain to me?
Computer Science
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
katieb
  • katieb
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
anonymous
  • anonymous
the code is supposed to force the microcontroller to produce outputs based on 8 different voltage interval with distance 6-22cm, 2cm per interval. the closer the object is to the sensor, the motor will run at higher speed, 0 speed is off and 8 speed is fastest. part of the code is as below: if(result < dist_6cm && result > dist_8cm){ SetDCPWM1( speed_8 ); PORTD = 0xFF; } why would the if uses <6 and'ed with >8? if the voltage should fall in between the interval 6-8cm, shouldnt the code be '...> dist_6 && ...< dist_8' ?
e.mccormick
  • e.mccormick
Yes, that seems illogical. For it to be less than a low number and more than a high number, both at once, makes no sense.
rsmith6559
  • rsmith6559
Although it's not written clearly, it will execute like: if( ( result < dist_6cm ) && ( result > dist_8cm ) ) The less than and greater than evaluate independently, and if either is false the if statement fails.

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

e.mccormick
  • e.mccormick
@rsmith6559 Exactly. It is only true is result is less than 6cm AND greater than 8cm. That seems contradictory. However, I would have to know what the sensor returns and what the values of dist_[6,8]cm are to really be sure if this contradictory.

Looking for something else?

Not the answer you are looking for? Search for more explanations.