example code using statis library for temperature measurement with LM35 and LM335

Dependencies:   mbed statis

temperatureSensor.cpp

Committer:
greletj
Date:
2012-11-20
Revision:
1:5821fa15d6ca
Child:
2:9517837c642d

File content as of revision 1:5821fa15d6ca:

/*-------------------------------------------------------------------------*/
/*                       temperatureSensor  class                          */
/*-------------------------------------------------------------------------*/
/*                    Ni-MH charger project US191 IRD                      */
/*-------------------------------------------------------------------------*/
/*                       Nov 2012 | J Grelet                               */
/*-------------------------------------------------------------------------*/

#include "temperatureSensor.h"
 
// constructor
// _pin(pin) means pass pin to the AnalogIn constructor
temperatureSensor::temperatureSensor(PinName pin, float delay, float convertion) : _pin(pin) { 
  
  _convertion = convertion;
  _scaleFactor = 100;
   
  // Attach a function to be called by the Ticker, specifiying the interval delay in seconds. 
  _ticker.attach(this, &temperatureSensor::toDo, delay);
}
 
// destructor
temperatureSensor::~temperatureSensor() {
}

// toDo method call by ticker
// read AnalogIn voltage and convert into temperature
void temperatureSensor::toDo(void) {
  _temperature = (_pin * _scaleFactor ) - _convertion;
}

// return temperature measurement
// add filtering with media and ring buffer
float temperatureSensor::read(void) {
  return _temperature;
}