Now it's time to see how our park assistant can work in practice. A possible implementation of the code is reported in the
chapter_02/distance_mon.sh script in the book's example code repository. The following code snippet shows the main code:
# Ok, do the job while sleep .1 ; do # Read the current distance from the sensor d=$($d_fun) dbg "d=$d" # Manage the LEDs leds_man $d done
The functioning is simple—the code periodically reads the distance from the sensor by using the function pointed by the
d_fun variable, and then turns the LEDs on and off, according to the value of the distance
d (in cm) by using the
d_fun variable holds the name of the function that should read the distance by using the ADC, that ...