Hi, I would like to make a C code for distance measurement using the C18 Compiler for MPLab. what would be the steps needed? would the following pseudocode do?
Make the I/O pin an Output
Bring LOW the pin that the PING rangefinder is connected
Bring the pin HIGH for 5 microseconds
Bring the pin LOW
Make the I/O pin an Input
Wait until the pin goes HIGH
Use a timer to see how much longer it takes for the pin to become LOW
The time it took to become low is now our raw distance ( in microseconds)
Divide Raw Distance by two since it includes the time for a return trip of the sonar
Raw distance * 2257 is our distance in cm
Please advise!
Raw distance * 889 is our distance in inches