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
Fork of SRF08 by
Diff: SRF08.h
- Revision:
- 1:76fb116fa28d
- Parent:
- 0:4e0a8193b92e
- Child:
- 2:ca82f89f415d
--- a/SRF08.h Thu Jul 05 09:53:18 2012 +0000 +++ b/SRF08.h Tue Jul 10 08:48:02 2012 +0000 @@ -26,6 +26,8 @@ #include "mbed.h" +#define RANGEBUFSIZE 5 + /* * The SRF08 is an Ultrasonic range finder, with an I2C interface that allows the measurement to be read directly in centimetres */ @@ -50,14 +52,46 @@ * Description: Destroys instance of SRF08 class */ ~SRF08(); - + + /* + * Function: startRanging + * Args: void + * Returns: void + * Description: Sends command to module to start ranging. + */ + void startRanging(); + + /* + * Function: rangingFinished + * Args: void + * Returns: Bool: whether ranging is finished + * Description: Checks if the ranging process on the module is finished + */ + bool rangingFinished(); + + /* + * Function: getRange + * Args: void + * Returns: int range + * Description: Range in cm. This function should only be called when ranging is finished, otherwise previous value is returned + */ + void getRange(); + /* * Function: readRange * Args: void * Returns: int range * Description: Reads the range register and converts it to a usable value */ - int read(); + int readRange(); + + /* + * Function: readBufRange + * Args: void + * Returns: int range + * Description: Reads the range register, adds it to an array and converts it to a filtered value + */ + //int readBufRange(); /* * Function: readLightIntensity @@ -90,7 +124,10 @@ private: I2C m_i2c; int m_addr; - + int rangeBuf[RANGEBUFSIZE]; + int rangeBufIndex; + + int getAverageBufRange(void); }; #endif