wireless sensor / PHtest

Fork of LinearAnalogSensors by Penn Electric

Embed: (wiki syntax)

« Back to documentation index

LinearTemp Class Reference

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:
pinAnalog input pin to which an LM335 or comparable linear temp sensor is connected
temp1Temperature (float in degrees C or F) of first calibration point
read1Mbed ADC reading (unsigned short) of first calibration point
temp2Temperature (float in degrees C or F) of second calibration point
read2Mbed 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:
pinAnalog input pin to which an LM335 or comparable linear temp sensor is connected
multiplierConversion multiplier to go from ADC reading as unsigned short to temperature (change in degrees / change in unsigned short)
offsetConversion 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.