A simply library for the LM75B I2C temperature sensor
Fork of LM75B by
LM75B.cpp@1:6a70c9303bbe, 2012-10-26 (annotated)
- Committer:
- chris
- Date:
- Fri Oct 26 21:40:51 2012 +0000
- Revision:
- 1:6a70c9303bbe
- Parent:
- 0:1be38995591b
- Child:
- 2:c5b96558c242
Removed header from .cpp file
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
chris | 0:1be38995591b | 1 | #include "LM75B.h" |
chris | 0:1be38995591b | 2 | |
chris | 0:1be38995591b | 3 | LM75B::LM75B(PinName sda, PinName scl) : i2c(sda, scl) |
chris | 0:1be38995591b | 4 | { |
chris | 0:1be38995591b | 5 | char cmd[2]; |
chris | 0:1be38995591b | 6 | cmd[0] = LM75B_Conf; |
chris | 0:1be38995591b | 7 | cmd[1] = 0x0; |
chris | 0:1be38995591b | 8 | i2c.write( LM75B_ADDR, cmd, 2); |
chris | 0:1be38995591b | 9 | } |
chris | 0:1be38995591b | 10 | |
chris | 0:1be38995591b | 11 | |
chris | 0:1be38995591b | 12 | |
chris | 0:1be38995591b | 13 | LM75B::~LM75B() |
chris | 0:1be38995591b | 14 | { |
chris | 0:1be38995591b | 15 | |
chris | 0:1be38995591b | 16 | } |
chris | 0:1be38995591b | 17 | |
chris | 0:1be38995591b | 18 | float LM75B::read() |
chris | 0:1be38995591b | 19 | { |
chris | 0:1be38995591b | 20 | char cmd[2]; |
chris | 0:1be38995591b | 21 | cmd[0] = LM75B_Temp; |
chris | 0:1be38995591b | 22 | |
chris | 0:1be38995591b | 23 | i2c.write( LM75B_ADDR, cmd, 1); // Send command string |
chris | 0:1be38995591b | 24 | i2c.read( LM75B_ADDR, cmd, 2); // Send command string |
chris | 0:1be38995591b | 25 | return ( float((cmd[0]<<8)|cmd[1]) / 256.0 ); |
chris | 0:1be38995591b | 26 | } |