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.cpp
- Revision:
- 5:abd72648aa5d
- Parent:
- 4:a11bd4ea3c18
--- 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