SRF02 sensor

Fork of SRF02 by Craig Evans

Files at this revision

API Documentation at this revision

Comitter:
Reniboy
Date:
Wed May 04 13:26:55 2016 +0000
Parent:
1:8e6587d88773
Commit message:
commit 1 ;

Changed in this revision

SRF02.cpp Show annotated file Show diff for this revision Revisions of this file
SRF02.h Show annotated file Show diff for this revision Revisions of this file
diff -r 8e6587d88773 -r 97ec40cfbf98 SRF02.cpp
--- a/SRF02.cpp	Sun Mar 08 14:21:40 2015 +0000
+++ b/SRF02.cpp	Wed May 04 13:26:55 2016 +0000
@@ -1,20 +1,20 @@
 /**
 @file SRF02.cpp
-
+ 
 @brief Member functions implementations
-
+ 
 */
 #include "mbed.h"
 #include "SRF02.h"
-
+ 
 SRF02::SRF02(PinName sdaPin, PinName sclPin)
 {
     i2c = new I2C(sdaPin,sclPin); // create new I2C instance and initialise
     i2c->frequency(400000);       // I2C Fast Mode - 400kHz
     leds = new BusOut(LED4,LED3,LED2,LED1);
-
+ 
 }
-
+ 
 int SRF02::getDistanceCm()
 {
     char data[2];
@@ -39,11 +39,11 @@
     ack = i2c->read(SRF02_R_ADD,data,2); 
     if (ack)
         error();  // if we don't receive acknowledgement, flash error message
-
+ 
     // high byte is first, then low byte, so combine into 16-bit value
     return (data[0] << 8) | data[1];
 }
-
+ 
 void SRF02::error()
 {
     while(1) {
diff -r 8e6587d88773 -r 97ec40cfbf98 SRF02.h
--- a/SRF02.h	Sun Mar 08 14:21:40 2015 +0000
+++ b/SRF02.h	Wed May 04 13:26:55 2016 +0000
@@ -64,13 +64,14 @@
     * @param sclPin - mbed SCL pin
     * 
     */
-    SRF02(PinName sdaPin, PinName sclPin);
+   SRF02(PinName sdaPin, PinName sclPin);
     /** Read distance in centimetres
     *
     * @returns distance in centimetres (int)
     * 
     */
     int getDistanceCm();
+    int averageDistance();
 
 private:
     /** Hangs in infinite loop flashing 'blue lights of death'