Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: PCT2075_Hello Brushless_STM3_ESC_2019_10 Alternator2020_06
base_class/I2CTempSensor.cpp
- Committer:
- okano
- Date:
- 2015-03-05
- Revision:
- 0:ae0333775d7e
File content as of revision 0:ae0333775d7e:
#include "I2CTempSensor.h"
I2CTempSensor::I2CTempSensor( PinName i2c_sda, PinName i2c_scl, char address )
: i2c_p( new I2C( i2c_sda, i2c_scl ) ), i2c( *i2c_p ), adr( address )
{
init();
}
I2CTempSensor::I2CTempSensor( I2C &i2c_obj, char address )
: i2c_p( NULL ), i2c( i2c_obj ), adr( address )
{
init();
}
I2CTempSensor::~I2CTempSensor()
{
if ( NULL != i2c_p )
delete i2c_p;
}
void I2CTempSensor::init( void )
{
char command[ 2 ];
command[ 0 ] = LM75B_Conf;
command[ 1 ] = 0x00;
i2c.write( adr, command, 2 );
}
short I2CTempSensor::read16( void )
{
char command[ 2 ];
command[ 0 ] = LM75B_Temp;
i2c.write( adr, command, 1 ); // Send command string
i2c.read( adr, command, 2 ); // read two bytes data
return ( (command[ 0 ] << 8)| command[1] );
}