Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
BeagleBone Home Automation Blueprints

You're reading from  BeagleBone Home Automation Blueprints

Product type Book
Published in Feb 2016
Publisher
ISBN-13 9781783986026
Pages 378 pages
Edition 1st Edition
Languages
Author (1):
Rodolfo Giometti Rodolfo Giometti
Profile icon Rodolfo Giometti

Table of Contents (18) Chapters

The distance monitor


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 leds_man function.

The d_fun variable holds the name of the function that should read the distance by using the ADC, that is, read_adc, or the name of the function that uses the serial port, that is, read_tty. The following are the two functions:

function read_adc () {
   n=$(cat $ADC_DEV)

   d=$(bc -l <<< "$k * 3.3 * $n/4095 / 0.00161")
 ...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}