Seeed Grove Temperature sensor component library
Dependents: Hello-grove-temperature-sensor Wio_3G_HTTP-POST-example Wio_3G_example sgam-lib ... more
Grove_temperature.cpp
00001 00002 /** 00003 ****************************************************************************** 00004 * @file Grove_temperature.cpp 00005 * @author Toyomasa Watarai 00006 * @version V1.0.0 00007 * @date 6 Aug 2018 00008 * @brief Seeed grove temperature sensor class implementation 00009 ****************************************************************************** 00010 * @attention 00011 * 00012 * Licensed under the Apache License, Version 2.0 (the "License"); 00013 * you may not use this file except in compliance with the License. 00014 * You may obtain a copy of the License at 00015 * 00016 * http://www.apache.org/licenses/LICENSE-2.0 00017 * 00018 * Unless required by applicable law or agreed to in writing, software 00019 * distributed under the License is distributed on an "AS IS" BASIS, 00020 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00021 * See the License for the specific language governing permissions and 00022 * limitations under the License. 00023 */ 00024 00025 #include "Grove_temperature.h" 00026 00027 Grove_temperature::Grove_temperature(PinName ain) 00028 : _ain(ain) 00029 { 00030 } 00031 00032 Grove_temperature::~Grove_temperature() 00033 { 00034 } 00035 00036 float Grove_temperature::getTemperature() 00037 { 00038 const int B = 4275; // B value of the thermistor 00039 const int R0 = 100000; // R0 = 100k 00040 00041 float R = 1.0f/_ain.read() - 1.0f; 00042 R = R0*R; 00043 00044 float temperature = 1.0/(log(R/R0)/B+1/298.15)-273.15; // convert to temperature via datasheet 00045 return temperature; 00046 }
Generated on Wed Jul 13 2022 09:15:19 by 1.7.2