arduino , ultrasonic sensors, vibration motor

Hi

We want u to tell us ur comment about the code…

It is not posted properly.
It is not well commented (though the position of the one comment is where I prefer comments; I hate comments at the end of a line of code).
Reading the sensor should be done in a function, not in loop(). When adding the additional sensors, adding two more calls to a function is FAR better than copy/pasting a dozen lines of code.

 if(distance <= 60 && distance >= 45)

Do you think that way? How would you describe the intent of this code? Most people would think “if the distance is between 45 and 60…” but the code says “if the distance is between 60 and 45…”. Code that reads the way people naturally express things is easier yo write, maintain, and follow.

Proper indenting would be good. Tools + Auto Format is so easy to use that poor indenting won’t be tolerated here.

I’d use proper sequencing of the distances, e.g.

if (distance < 30) ...
else if (distance < 45) ...
else if (distance < 60) ...
else /* >=60 */ ...

Please use code tags ‘</>’ to post code.

PaulS:
It is not posted properly.
It is not well commented (though the position of the one comment is where I prefer comments; I hate comments at the end of a line of code).
Reading the sensor should be done in a function, not in loop(). When adding the additional sensors, adding two more calls to a function is FAR better than copy/pasting a dozen lines of code.

 if(distance <= 60 && distance >= 45)

Do you think that way? How would you describe the intent of this code? Most people would think “if the distance is between 45 and 60…” but the code says “if the distance is between 60 and 45…”. Code that reads the way people naturally express things is easier yo write, maintain, and follow.

Proper indenting would be good. Tools + Auto Format is so easy to use that poor indenting won’t be tolerated here.

Thanks a lot for replying … ur comments will help us so much in our senior project… we’re new beginners in arduino world and we need some one to help us in coding … Can I communicate with you via e-mail?

DrDiettrich:
I’d use proper sequencing of the distances, e.g.

if (distance < 30) ...

else if (distance < 45) …
else if (distance < 60) …
else /* >=60 */ …



Please use code tags '</>' to post code.

Thanks a lot for replying … ur comments will help us so much in our senior project… we’re new beginners in arduino world and we need some one to help us in coding … Can I communicate with you via e-mail?

but if i do like what u said ,
if the distance is less than 45 for example and it is also less than 30… which if statement will be implemented??

Can I communicate with you via e-mail?

PM me, and I'll gibe you my email address.

zahra234: but if i do like what u said , if the distance is less than 45 for example and it is also less than 30.. which if statement will be implemented??

The first matching statement (true condition) will execute, all following tests are bypassed then by else if.