Grelet Jacques
/
Ni-MH_V3
example code using statis library for temperature measurement with LM35 and LM335
Diff: temperatureSensor.cpp
- Revision:
- 1:5821fa15d6ca
- Child:
- 2:9517837c642d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/temperatureSensor.cpp Tue Nov 20 12:10:39 2012 +0000 @@ -0,0 +1,36 @@ +/*-------------------------------------------------------------------------*/ +/* 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; +} \ No newline at end of file