A simply library for the LM75B I2C temperature sensor

Dependencies:   Joystick

Dependents:   mbed-os-example-mbed5-explore_peripherals

Committer:
tristium
Date:
Fri Feb 12 09:27:56 2021 +0000
Revision:
2:8a8bca9da65f
Parent:
1:6a70c9303bbe
Last assigment

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 }