version for edu_robot TM
Fork of SRF02 by
Revision 2:9da88e2889b6, committed 2014-02-26
- Comitter:
- BjornVB
- Date:
- Wed Feb 26 08:29:45 2014 +0000
- Parent:
- 1:6b978ea41787
- Commit message:
- Project files for EDU robot
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 6b978ea41787 -r 9da88e2889b6 SRF02.cpp --- a/SRF02.cpp Fri Dec 16 14:09:37 2011 +0000 +++ b/SRF02.cpp Wed Feb 26 08:29:45 2014 +0000 @@ -3,6 +3,7 @@ /* Creates an instance of class. Setting the pin used for I2C, the address of device and the measure range type. */ SRF02::SRF02(PinName sda, PinName scl, int addr, char type) : _i2c(sda, scl), _addr(addr) { + _typem = type; } @@ -19,6 +20,7 @@ char result[2]; command[0] = 0x00; // Set the command register + command[1] = _typem; // Ranging results in type indicated in a costructor _i2c.write(_addr, command, 2); // Send the command to start a ranging burst @@ -31,4 +33,4 @@ float range = (result[0]<<8)+result[1]; // Convert the two byte in a float value return range; -} +} \ No newline at end of file
diff -r 6b978ea41787 -r 9da88e2889b6 SRF02.h --- a/SRF02.h Fri Dec 16 14:09:37 2011 +0000 +++ b/SRF02.h Wed Feb 26 08:29:45 2014 +0000 @@ -28,9 +28,6 @@ #include "mbed.h" -#define INCHES_RESULT 0x50 // For result in inches -#define CENTIMETERS_RESULT 0x51 // For result in centimeters -#define MICROSECONDS_RESULT 0x52 // For result in micro-seconds /** Library for the SRF02 Ultrasonic Ranger Sensor, using the I2C bus for the * comunication. Remeber that sensor can function in serial mode if MODE pin * is connected to the ground, but this libary not support this mode. @@ -41,7 +38,7 @@ * #include "mbed.h" * #include "SRF02.h" * // Create instance of class SRF02 for device at address 0xE0 and take mesure in cm - * SRF02 srf02(p28, p27, 0xE0, 1); + * SRF02 srf02(p28, p27, 0xE0, 0x51); * DigitalOut led1(LED1); * * int main() @@ -59,13 +56,13 @@ class SRF02 { public: - enum measure_type{INCHES=0x050,CENTIMETERS=0x51,MICROSECONDS=0x52}; + //enum _typem{INCHES=0x050,CENTIMETERS=0x51,MICROSECONDS=0x52}; /** Creates an instance of class. Setting the pin used for I2C, the address of device and the measure range type. * * @param sda A pin used for SDA I2C signal. * @param scl A pin used for SCL I2C signal. * @param addr The address of I2C SRF02 device. - * @param measure_type The of mesure response (0-inches,1-centimeters,2-micro-seconds). + * @param measure_type The of mesure response (0x50-inches,0x51-centimeters,0x52-micro-seconds). */ SRF02(PinName sda, PinName scl, int addr, char type);