Question: Write a program, sonar _ range _ finder.c , compiled with GCC on the RPi , that performs the following steps: a . b .

Write a program, sonar_range_finder.c, compiled with GCC on the RPi , that performs the following
steps:
a.
b.
c.
d.
e.
f.
g.
h.
i.
j.
k.
l.
m.
n.
o.
p.
q.
r.
Include the pigpio.h, stdio.h, and unistd.h files
Initializes the RPI GPIO by calling gpioInitialize()
Initializes the TRIGGER pin to be an output by calling gpioSetMode()
Initializes the ECHO pin to be an input by calling gpioSetMode(), and gpioSetPullUpDown(), Use
PI_PUD_OFF in the call to gpioSetPullIpDown()
Start a while(1) loop.
Set Trig signal high (1)
Call sleep(1) to delay for a second
Set Trig signal low (0)
Zero a count variable
Enter a while loop that waits until the Echo signal goes high. There is no code in the while loop
Call gpioTime to store the current time.
Enter another while loop that waits until the Echo signal goes low. The while loop contains code
that increments the count variable
Call gpioTime() to capture the current time. The elapsed time is then calculated by subtracting
the time stored in step (k) from the time recorded in this step.
Print out the count value and the elapsed time (calculated in step (m)).
Calculate the distance using the elapsed time and the speed of sound. Note how the count of
executed instructions is roughly proportional to the elapsed time.
Print out the distance in cm and inches. (As a check of your results, the desk is about 4 feet or
122 cm in length. The distance from the desk to the floor is about 24 inches.)
End the loop started in step e
Call gpioTerminate(). Note this function will never execute, because the infinite loop above will
only exit with a abort entered by the user.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!