A simply library for the LM75B I2C temperature sensor (forked from "chris/LM75B").
Fork of LM75B by
LM75B.cpp@2:1d73b9205f1b, 2016-02-03 (annotated)
- Committer:
- co657_frmb
- Date:
- Wed Feb 03 02:15:03 2016 +0000
- Revision:
- 2:1d73b9205f1b
- Parent:
- 1:6a70c9303bbe
a small update perhaps
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 |
co657_frmb | 2:1d73b9205f1b | 25 | return ( float((cmd[0]<<8)|cmd[1]) / (float)256.0 ); |
chris | 0:1be38995591b | 26 | } |