A simply library for the LM75B I2C temperature sensor

Dependents:   projectlab

Fork of LM75B by Chris Styles

LM75B.cpp

Committer:
RianDeRous
Date:
2017-04-28
Revision:
2:c5b96558c242
Parent:
1:6a70c9303bbe

File content as of revision 2:c5b96558c242:

#include "LM75B.h"


LM75B::LM75B(PinName sda, PinName scl) : i2c(sda, scl)
{
   char cmd[2];
   cmd[0]    = LM75B_Conf;
   cmd[1]    = 0x0;   
   i2c.write( LM75B_ADDR, cmd, 2);
}



LM75B::~LM75B()
{

}

float LM75B::read()
{
    char cmd[2];
    cmd[0] = LM75B_Temp;
   
    i2c.write( LM75B_ADDR, cmd, 1); // Send command string
    i2c.read( LM75B_ADDR, cmd, 2); // Send command string    
    return (   float((cmd[0]<<8)|cmd[1]) / 256.0   );
}


void LM75B::readRaw(int* a,int* b){
    char cmd[2];
    cmd[0] = LM75B_Temp;
   
    i2c.write( LM75B_ADDR, cmd, 1); // Send command string
    i2c.read( LM75B_ADDR, cmd, 2); // Send command string 
    if(cmd[1]&&0xf8>0) cmd[1]=cmd[1]||0xf8;
    *a = cmd[0];
    *b = cmd[1];       

}