A feature complete driver for the LM75B temperature sensor from NXP.

Dependents:   app-board-TempAlarm LM75B IoTWorkshopSensors EduRobot ... more

Revision:
12:fc27dc535ea9
Parent:
11:9bd544dd9e07
Child:
13:27c19044ace6
--- a/LM75B.h	Wed Aug 28 17:42:55 2013 +0000
+++ b/LM75B.h	Mon Sep 16 21:32:18 2013 +0000
@@ -27,7 +27,8 @@
  * #include "mbed.h"
  * #include "LM75B.h"
  *
- * LM75B sensor(p28, p27, LM75B::ADDRESS_0);
+ * //Create an LM75B object at the default address (ADDRESS_0)
+ * LM75B sensor(p28, p27);
  *
  * int main()
  * {
@@ -36,17 +37,14 @@
  *         printf("Device detected!\n");
  *
  *         while (1) {
- *             //Read the temperature
- *             float temp = sensor.temp();
- *
- *             //Print the temperature
- *             printf("Temp = %.3f\n", temp);
+ *             //Print the current temperature
+ *             printf("Temp = %.3f\n", (float)sensor);
  *
  *             //Sleep for 0.5 seconds
  *             wait(0.5);
  *         }
  *     } else {
- *         printf("Device not detected!\n");
+ *         error("Device not detected!\n");
  *     }
  * }
  * @endcode
@@ -101,9 +99,9 @@
      *
      * @param sda The I2C data pin.
      * @param scl The I2C clock pin.
-     * @param addr The I2C slave address.
+     * @param addr The I2C slave address (defaults to ADDRESS_0).
      */
-    LM75B(PinName sda, PinName scl, Address addr);
+    LM75B(PinName sda, PinName scl, Address addr = ADDRESS_0);
 
     /** Probe for the LM75B and reset it to default configuration if present
      *
@@ -191,6 +189,16 @@
      */
     float temp(void);
 
+#ifdef MBED_OPERATORS
+    /** A shorthand for temp()
+     *
+     * @returns The current temperature measurement in °C.
+     */
+    operator float() {
+        return temp();
+    }
+#endif
+
 private:
     //I2C register addresses
     enum Register {