Question: Write a program, sonar _ range _ finder.c , compiled with GCC on the RPi , that performs the following steps: a . Include the
Write a program, sonarrangefinder.c compiled with GCC on the RPi that performs the following steps:
a Include the pigpio.h stdio.h and unistd.h files
b Initializes the RPI GPIO by calling gpioInitialize
c Initializes the TRIGGER pin to be an output by calling gpioSetMode
d Initializes the ECHO pin to be an input by calling gpioSetMode and gpioSetPullUpDown Use PIPUDOFF in the call to gpioSetPullIpDown
e Start a while loop.
f Set Trig signal high
g Call sleep to delay for a second
h Set Trig signal low
i Zero a count variable
j Enter a while loop that waits until the Echo signal goes high. There is no code in the while loop
k Call gpioTime to store the current time.
l Enter another while loop that waits until the Echo signal goes low. The while loop contains code that increments the count variable
m 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.
n Print out the count value and the elapsed time calculated in step m
o 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.
p Print out the distance in cm and inches. As a check of your results, the desk is about feet or cm in length. The distance from the desk to the floor is about inches.
q End the loop started in step e
r 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
