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@1:aee37a51ccbb, 2018-08-06 (annotated)
- Committer:
- MACRUM
- Date:
- Mon Aug 06 09:24:54 2018 +0000
- Revision:
- 1:aee37a51ccbb
- Parent:
- 0:d4056a86ef8c
Code clean up
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MACRUM | 0:d4056a86ef8c | 1 | |
MACRUM | 0:d4056a86ef8c | 2 | /** |
MACRUM | 0:d4056a86ef8c | 3 | ****************************************************************************** |
MACRUM | 0:d4056a86ef8c | 4 | * @file Grove_temperature.cpp |
MACRUM | 0:d4056a86ef8c | 5 | * @author Toyomasa Watarai |
MACRUM | 0:d4056a86ef8c | 6 | * @version V1.0.0 |
MACRUM | 0:d4056a86ef8c | 7 | * @date 6 Aug 2018 |
MACRUM | 0:d4056a86ef8c | 8 | * @brief Seeed grove temperature sensor class implementation |
MACRUM | 0:d4056a86ef8c | 9 | ****************************************************************************** |
MACRUM | 0:d4056a86ef8c | 10 | * @attention |
MACRUM | 0:d4056a86ef8c | 11 | * |
MACRUM | 0:d4056a86ef8c | 12 | * Licensed under the Apache License, Version 2.0 (the "License"); |
MACRUM | 0:d4056a86ef8c | 13 | * you may not use this file except in compliance with the License. |
MACRUM | 0:d4056a86ef8c | 14 | * You may obtain a copy of the License at |
MACRUM | 0:d4056a86ef8c | 15 | * |
MACRUM | 0:d4056a86ef8c | 16 | * http://www.apache.org/licenses/LICENSE-2.0 |
MACRUM | 0:d4056a86ef8c | 17 | * |
MACRUM | 0:d4056a86ef8c | 18 | * Unless required by applicable law or agreed to in writing, software |
MACRUM | 0:d4056a86ef8c | 19 | * distributed under the License is distributed on an "AS IS" BASIS, |
MACRUM | 0:d4056a86ef8c | 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
MACRUM | 0:d4056a86ef8c | 21 | * See the License for the specific language governing permissions and |
MACRUM | 0:d4056a86ef8c | 22 | * limitations under the License. |
MACRUM | 0:d4056a86ef8c | 23 | */ |
MACRUM | 1:aee37a51ccbb | 24 | |
MACRUM | 1:aee37a51ccbb | 25 | #include "Grove_temperature.h" |
MACRUM | 0:d4056a86ef8c | 26 | |
MACRUM | 0:d4056a86ef8c | 27 | Grove_temperature::Grove_temperature(PinName ain) |
MACRUM | 0:d4056a86ef8c | 28 | : _ain(ain) |
MACRUM | 0:d4056a86ef8c | 29 | { |
MACRUM | 0:d4056a86ef8c | 30 | } |
MACRUM | 0:d4056a86ef8c | 31 | |
MACRUM | 0:d4056a86ef8c | 32 | Grove_temperature::~Grove_temperature() |
MACRUM | 0:d4056a86ef8c | 33 | { |
MACRUM | 0:d4056a86ef8c | 34 | } |
MACRUM | 0:d4056a86ef8c | 35 | |
MACRUM | 0:d4056a86ef8c | 36 | float Grove_temperature::getTemperature() |
MACRUM | 0:d4056a86ef8c | 37 | { |
MACRUM | 0:d4056a86ef8c | 38 | const int B = 4275; // B value of the thermistor |
MACRUM | 0:d4056a86ef8c | 39 | const int R0 = 100000; // R0 = 100k |
MACRUM | 0:d4056a86ef8c | 40 | |
MACRUM | 0:d4056a86ef8c | 41 | float R = 1.0f/_ain.read() - 1.0f; |
MACRUM | 0:d4056a86ef8c | 42 | R = R0*R; |
MACRUM | 0:d4056a86ef8c | 43 | |
MACRUM | 0:d4056a86ef8c | 44 | float temperature = 1.0/(log(R/R0)/B+1/298.15)-273.15; // convert to temperature via datasheet |
MACRUM | 0:d4056a86ef8c | 45 | return temperature; |
MACRUM | 0:d4056a86ef8c | 46 | } |