C++ file for display control
Dependencies: 4DGL mbed ConfigFile
Fork of 4DGLtest by
Diff: temperature.cpp
- Revision:
- 9:311b6676272d
- Parent:
- 7:779c5b8d3b14
--- a/temperature.cpp Wed Jul 09 07:52:00 2014 +0000 +++ b/temperature.cpp Fri Jul 11 11:08:02 2014 +0000 @@ -1,24 +1,23 @@ #include "mbed.h" +#include "temperature.h" // Read temperature from LM75BD -//I2C i2c(p28, p27);//use same pins as KBD - -extern I2C CDU_I2C; //I2C bus for keyboard/temp chip. Defined in keyboard.cpp -const int addr = 0x90; //Default hardware address of LM75B chip +extern I2C CDU_I2C; //I2C bus on i2c(p28, p27) for keyboard/temp chip. Defined in keyboard.cpp +const int CDU_TMP_ADRS = 0x90; //Default hardware address of LM75B chip float CDU_GetTemp() { char cmd[2]; //Init LM75B - cmd[0] = 0x01; //Pointer byte (0x01=configuration register) - cmd[1] = 0x00; //Configuration byte (0x00=normal configuration) - CDU_I2C.write(addr, cmd, 2); //Write bytes to bus + cmd[0] = REG_CONFIG; //Pointer byte (0x01=configuration register) + cmd[1] = CONFIG_NORMAL; //Configuration byte (0x00=normal configuration) + CDU_I2C.write(CDU_TMP_ADRS, cmd, 2); //Write bytes to bus //Read temperature - cmd[0] = 0x00; //Pointer byte (0x00=temperature register) - CDU_I2C.write(addr, cmd, 1); //write to device - CDU_I2C.read(addr, cmd, 2); //read temperature 2 data bytes + cmd[0] = REG_TEMP; //Pointer byte (0x00=temperature register) + CDU_I2C.write(CDU_TMP_ADRS, cmd, 1); //write to device + CDU_I2C.read(CDU_TMP_ADRS, cmd, 2); //read temperature 2 data bytes /* Convert from 2's complement to Degrees Celsius @@ -28,3 +27,4 @@ float tmp = (float((cmd[0]<<8)|cmd[1]) / 256.0); return ( tmp ); } +