Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

edr1c Group Title

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?

  • one year ago
  • one year ago

  • This Question is Closed
  1. edr1c Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    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' ?

    • one year ago
  2. e.mccormick Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

    • one year ago
  3. rsmith6559 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

    • one year ago
  4. e.mccormick Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    @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.

    • one year ago
    • Attachments:

See more questions >>>

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.