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
I2CTempSensor.cpp
00001 #include "I2CTempSensor.h" 00002 00003 I2CTempSensor::I2CTempSensor( PinName i2c_sda, PinName i2c_scl, char address ) 00004 : i2c_p( new I2C( i2c_sda, i2c_scl ) ), i2c( *i2c_p ), adr( address ) 00005 { 00006 init(); 00007 } 00008 00009 I2CTempSensor::I2CTempSensor( I2C &i2c_obj, char address ) 00010 : i2c_p( NULL ), i2c( i2c_obj ), adr( address ) 00011 { 00012 init(); 00013 } 00014 00015 I2CTempSensor::~I2CTempSensor() 00016 { 00017 if ( NULL != i2c_p ) 00018 delete i2c_p; 00019 } 00020 00021 void I2CTempSensor::init( void ) 00022 { 00023 char command[ 2 ]; 00024 00025 command[ 0 ] = LM75B_Conf; 00026 command[ 1 ] = 0x00; 00027 00028 i2c.write( adr, command, 2 ); 00029 } 00030 00031 short I2CTempSensor::read16( void ) 00032 { 00033 char command[ 2 ]; 00034 00035 command[ 0 ] = LM75B_Temp; 00036 00037 i2c.write( adr, command, 1 ); // Send command string 00038 i2c.read( adr, command, 2 ); // read two bytes data 00039 00040 return ( (command[ 0 ] << 8)| command[1] ); 00041 }
Generated on Wed Jul 13 2022 08:50:39 by
1.7.2