A simply library for the LM75B I2C temperature sensor

Dependents:   LM75B-HelloWorld app-board-Sprint-SMS-LM75B SprintUSBModemWebsocketTest-Temp app-board-Ethernet-Websocket ... more

Committer:
chris
Date:
Fri Oct 26 21:40:51 2012 +0000
Revision:
1:6a70c9303bbe
Parent:
0:1be38995591b
Removed header from .cpp file

Who changed what in which revision?

UserRevisionLine numberNew 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 }