Hello world code for PCT2075 and LM75B component class library. The PCT2075 is a temperature-to-digital converter featuring +/-1 degree-C accuracy over -25 degree-C to +100 degree-C range. It uses an on-chip band gap temperature sensor and Sigma-Delta A-to-D conversion technique with an overtemperature detection output that is a drop-in replacement for other LM75 series thermal sensors.

Dependencies:   PCT2075 mbed

Files at this revision

API Documentation at this revision

Comitter:
okano
Date:
Fri Feb 27 12:35:30 2015 +0000
Parent:
0:3c3d4c5ac8e9
Child:
2:edd678dcf504
Commit message:
could built, no test done

Changed in this revision

PCT2075/PCT2075.cpp Show annotated file Show diff for this revision Revisions of this file
PCT2075/PCT2075.h Show annotated file Show diff for this revision Revisions of this file
PCT2075/base_class/I2CTempSensor.cpp Show annotated file Show diff for this revision Revisions of this file
PCT2075/base_class/I2CTempSensor.h Show annotated file Show diff for this revision Revisions of this file
--- a/PCT2075/PCT2075.cpp	Fri Feb 27 10:47:24 2015 +0000
+++ b/PCT2075/PCT2075.cpp	Fri Feb 27 12:35:30 2015 +0000
@@ -17,11 +17,11 @@
 {
 }
 
-PCT2075::operator float( void )
+float PCT2075::read( void )
 {
-//    typedef I2CTempSensor base;
+    typedef I2CTempSensor base;
 
-    return( base::read() / 256.0 );
+    return( base::read16() / 256.0 );
 }
 
 PCT2075::operator float( void )
--- a/PCT2075/PCT2075.h	Fri Feb 27 10:47:24 2015 +0000
+++ b/PCT2075/PCT2075.h	Fri Feb 27 12:35:30 2015 +0000
@@ -14,6 +14,9 @@
  *      http://i2c_sda.nxp.com/documents/data_sheet/LM75B.pdf
  */
 
+#ifndef MBED_PCT2075_H
+#define MBED_PCT2075_H
+
 #include    "mbed.h"
 #include    "I2CTempSensor.h"
 
@@ -53,9 +56,9 @@
 public:
     /** I2Cピンとスレーブアドレスを指定し,インスタンスを作成します
      *
-     * @param i2c_sda I2C-bus i2c_sdaピン
-     * @param i2c_scl I2C-bus i2c_sclピン
-     * @param i2c_address (オプション) I2C-bus スレーブアドレス (デフォルト: 0x90)
+     * @param i2c_sda       I2C-bus i2c_sdaピン
+     * @param i2c_scl       I2C-bus i2c_sclピン
+     * @param i2c_address   (オプション) I2C-bus スレーブアドレス (デフォルト: 0x90)
      */
     PCT2075( PinName i2c_sda, PinName i2c_scl, char i2c_address = DEFAULT_I2C_SLAVE_ADDRESS );
 
@@ -74,21 +77,20 @@
      *
      *  @return 摂氏温度を返します(float型)
      */
-    float   read( void );
+    virtual float   read( void );
 
     /** 温度の読み出し
      *
      *  @return オブジェクトが読みだした値を返すようにしています
      */
-    operator float( void );
+    virtual operator float( void );
 
 private:
     /** デフォルト・スレーブアドレス */
     enum {
         DEFAULT_I2C_SLAVE_ADDRESS   = 0x90
     };
+};
 
-    I2C     *i2c_p;
-    I2C     &i2c;
-    char    adr;
-};
+#endif  //  MBED_PCT2075_H
+
--- a/PCT2075/base_class/I2CTempSensor.cpp	Fri Feb 27 10:47:24 2015 +0000
+++ b/PCT2075/base_class/I2CTempSensor.cpp	Fri Feb 27 12:35:30 2015 +0000
@@ -28,7 +28,7 @@
     i2c.write( adr, command, 2 );
 }
 
-short I2CTempSensor::read( void )
+short I2CTempSensor::read16( void )
 {
     char    command[ 2 ];
 
--- a/PCT2075/base_class/I2CTempSensor.h	Fri Feb 27 10:47:24 2015 +0000
+++ b/PCT2075/base_class/I2CTempSensor.h	Fri Feb 27 12:35:30 2015 +0000
@@ -1,5 +1,3 @@
-
-
 /** PCT2075 and LM75B component class library
  *  PCT2075 と LM75B 用のコンポーネント・クラス・ライブラリです
  *
@@ -16,6 +14,9 @@
  *      http://www.nxp.com/documents/data_sheet/LM75B.pdf
  */
 
+#ifndef MBED_I2CTempSensor_H
+#define MBED_I2CTempSensor_H
+
 #include "mbed.h"
 
 /** I2CTempSensor class library クラスライブラリ
@@ -27,9 +28,12 @@
 
 class I2CTempSensor
 {
+public:
+    virtual float   read( void )    = 0;
+    virtual operator float( void )  = 0;
+
 protected:
 
-
     /** LM75Bのレジスタ名とアドレス */
     enum command_reg    {
         LM75B_Temp  = 0x00,
@@ -65,10 +69,13 @@
      *
      *  @return 摂氏温度を返します(float型)
      */
-    short   read( void );
+    short   read16( void );
 
 private:
     I2C     *i2c_p;
     I2C     &i2c;
     char    adr;
 };
+
+#endif  //  MBED_I2CTempSensor_H
+