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.
Fork of LinearAnalogSensors by
LinearTemp Class Reference
This library is designed to work with devices like the LM335 temperature sensor. More...
#include <LinearTemp.h>
Public Member Functions | |
| LinearTemp (PinName pin, float temp1, unsigned short read1, float temp2, unsigned short read2) | |
| Create a calibrated temperature sensor object connected to an Analog input pin. | |
| LinearTemp (PinName pin, float multiplier, float offset) | |
| Create a calibrated temperature sensor object connected to an Analog input pin. | |
| float | readTemp () |
| Returns a new median-filtered, converted reading from the sensor. | |
| float | getTemp () |
| Return the last calculated and stored temperature. | |
| operator float () | |
| An operator shorthand for readTemp() to calculate filtered temperature. | |
Detailed Description
This library is designed to work with devices like the LM335 temperature sensor.
There are only two requirements for compatibility of a device with this library: 1) It must be a sensor device that has an analog voltage output. 2) The physical quantity measured must vary linearly with the analog voltage. The LM335 which creates an analog voltage proportional to temperature can work very well with this library using the nominal multiplier of 0.0050354 and offset of -273.15 or by providing two calibration points to the constuctor to generate a linear response. It samples the sensor 9 times and uses the median to minimize the effect of poor ADC readings and sudden changes.
Example:
LinearTemp mysensor(p20, 0.0050354, -273.15); // Setup a LM335 temp sensor on pin 20 DigitalOut myled(LED1); int main() { while(1) { // Light LED if filtered temperature is greater than 45 degrees Celsius if (mysensor > 45) myled = 1; else myled = 0; } }
Definition at line 48 of file LinearTemp.h.
Constructor & Destructor Documentation
| LinearTemp | ( | PinName | pin, |
| float | temp1, | ||
| unsigned short | read1, | ||
| float | temp2, | ||
| unsigned short | read2 | ||
| ) |
Create a calibrated temperature sensor object connected to an Analog input pin.
- Parameters:
-
pin Analog input pin to which an LM335 or comparable linear temp sensor is connected temp1 Temperature (float in degrees C or F) of first calibration point read1 Mbed ADC reading (unsigned short) of first calibration point temp2 Temperature (float in degrees C or F) of second calibration point read2 Mbed ADC reading (unsigned short) of second calibration point
Definition at line 25 of file LinearTemp.cpp.
| LinearTemp | ( | PinName | pin, |
| float | multiplier, | ||
| float | offset | ||
| ) |
Create a calibrated temperature sensor object connected to an Analog input pin.
- Parameters:
-
pin Analog input pin to which an LM335 or comparable linear temp sensor is connected multiplier Conversion multiplier to go from ADC reading as unsigned short to temperature (change in degrees / change in unsigned short) offset Conversion offset (positive or negative)
Definition at line 32 of file LinearTemp.cpp.
Member Function Documentation
| float getTemp | ( | ) |
Return the last calculated and stored temperature.
- Returns:
- Last stored temperature (float) in degrees C or F as designated by the calibration points
Definition at line 59 of file LinearTemp.cpp.
| operator float | ( | ) |
An operator shorthand for readTemp() to calculate filtered temperature.
Definition at line 75 of file LinearTemp.h.
| float readTemp | ( | ) |
Returns a new median-filtered, converted reading from the sensor.
- Returns:
- New temperature (float) in degrees C or F as designated by the calibration points
Definition at line 39 of file LinearTemp.cpp.
Generated on Wed Jul 13 2022 23:18:42 by
1.7.2
