Library for interfacing the SRF08 ultrasonic range sensor. Most functions of the SRF08 are covered, including interrupt-based waiting for the ranging process to finish

Dependents:   Project6

Fork of SRF08 by Brent Dekker

Files at this revision

API Documentation at this revision

Comitter:
el13tjoc
Date:
Sun May 10 01:55:56 2015 +0000
Parent:
4:a11bd4ea3c18
Commit message:
SRF08 Library;

Changed in this revision

SRF08.cpp Show annotated file Show diff for this revision Revisions of this file
SRF08.h Show annotated file Show diff for this revision Revisions of this file
diff -r a11bd4ea3c18 -r abd72648aa5d SRF08.cpp
--- a/SRF08.cpp	Wed Jul 11 08:11:34 2012 +0000
+++ b/SRF08.cpp	Sun May 10 01:55:56 2015 +0000
@@ -42,11 +42,11 @@
  * Returns:     void
  * Description: Sends command to module to start ranging.
  */
-void SRF08::startRanging() {
+void SRF08::startRanging(char rangingType) {
     //Create a two byte command. The first first byte is the register address
     // on the SRF08 to write to. The second byte is the command which is written
     // to that address ("Start ranging in cm" in this case).
-    const char command[] = {0x00, 0x51};
+    char command[] = {0x00, rangingType};
     i2cMod.write(i2cAddress, command, 2);
     this->rangingBusy = true;
     rangeTimeout.attach(this, &SRF08::setRangingFinished, 0.07);
@@ -70,7 +70,7 @@
  * Description: Range in cm. This function should only be called when ranging is finished, otherwise previous value is returned
  */
 int SRF08::getRange() {
-    //while (!rangingFinished() ) wait(0.01);   //Wait until ranging is finished
+    while (!rangingFinished() ) wait(0.01);   //Wait until ranging is finished
     const char command[]  = {0x02};           //Address of range register
     char response[] = {0x00, 0x00};
     i2cMod.write(i2cAddress, command, 1, 1);  //Send command
diff -r a11bd4ea3c18 -r abd72648aa5d SRF08.h
--- a/SRF08.h	Wed Jul 11 08:11:34 2012 +0000
+++ b/SRF08.h	Sun May 10 01:55:56 2015 +0000
@@ -25,6 +25,10 @@
 
 #include "mbed.h"
 
+#define INCHES 0x50 //Ranging Mode - Result in inches
+#define CM  0x51 //Ranging Mode - Result in centimeters
+#define US  0x52 //Ranging Mode - Result in micro-seconds
+
 /**
  * The SRF08 is an ultrasonic range finder with an I2C interface that allows 
  * the measurement to be read directly in centimetres. More information can be
@@ -46,7 +50,7 @@
     /**
      * Send the "Start ranging in cm" command via I2C
      */
-    void startRanging();
+    void startRanging(char rangingType);
     
     /**
      * Checks if the module has finished ranging