TMP102 temperature sensor test using LPC824.

Dependencies:   test_TMP102 mbed

Revision:
2:40c813b1d6a3
Parent:
1:3241f6a5a51e
Child:
3:600dea808e48
--- a/main.cpp	Sun Nov 19 09:59:21 2017 +0000
+++ b/main.cpp	Sat Nov 25 03:28:22 2017 +0000
@@ -1,29 +1,12 @@
 #include "mbed.h"
-
-// TMP102 I2C slave address(ADD0 connected to GND)
-#define ADDR_TMP102     0x90
+#include "test_TMP102.h"
 
-// TMP102 registers
-#define TMP102_Temp     0x00
-#define TMP102_Conf     0x01
-#define TMP102_Tlow     0x02
-#define TMP102_Thigh    0x03
+test_TMP102 tmp102(dp4,dp5);
 
-// Init I2C (SDA: dp4, SCL: dp5)
-I2C i2c(dp4, dp5);
-
-int main() {    
+int main()
+{
     while(1) {
-        i2c.write(ADDR_TMP102, 0x00, 1); //Pointer to the temperature register
-
-        char reg[2]={0,0};
-        i2c.read(ADDR_TMP102, reg, 2); // read two bytes data
-
-        // calculate temperature
-        int16_t res = ((int8_t)reg[0] << 4) | ((uint8_t)reg[1] >> 4);
-        float temp = (float) ((float)res * 0.0625);
-
-        printf("Temp: %f\n\r", temp);
+        printf("Temp: %f\n\r", tmp102.read());
         wait(1.0);
     }
 }