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.
MLX90614.cpp
00001 #include "MLX90614.h" 00002 00003 MLX90614::MLX90614(PinName sda, PinName scl) 00004 { 00005 i2c_ = new I2C(sda, scl); 00006 i2c_->frequency(400000); 00007 } 00008 00009 MLX90614::MLX90614(I2C *i2c) : i2c_(i2c) { 00010 } 00011 00012 MLX90614::~MLX90614() { 00013 delete i2c_; 00014 } 00015 00016 float MLX90614::get_temp(uint8_t reg) { 00017 char cmd[3] = { 0 }; 00018 // read the temperature data (kelvin) 00019 cmd[0] = ram_access | reg; 00020 i2c_->write(default_addr,cmd,1,true); i2c_->read(default_addr,cmd,3); 00021 // convert to meaningful units, still in kelvin - just normalized 00022 return 0.02 * static_cast<float>((cmd[1]<<8)|cmd[0]); 00023 } 00024 00025 float MLX90614::read_temp(int select) { 00026 uint8_t reg_addrs[] = { T_ambient, T_obj1 }; 00027 float tt = 0.0; 00028 if (select == 0){ 00029 tt = get_temp(reg_addrs[0])-273.15; 00030 } 00031 if (select == 1){ 00032 tt = get_temp(reg_addrs[1])-273.15; 00033 } 00034 return tt; 00035 }
Generated on Tue Jul 12 2022 15:22:03 by
1.7.2