![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Сбор информации о погодных условиях
Dependencies: RF24 USBDevice mbed
Thermistor.cpp@2:ad2653bcf93f, 2015-10-22 (annotated)
- Committer:
- pro100kot14
- Date:
- Thu Oct 22 20:31:06 2015 +0000
- Revision:
- 2:ad2653bcf93f
- Parent:
- 1:8766173d267f
Added the class of information processing with photoresist with the interpretation of it as light levels.; Added lighting classification as enum Illumination; Fixed bug in calculation of the temperature read from thermistor.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pro100kot14 | 1:8766173d267f | 1 | #include "Thermistor.h" |
pro100kot14 | 1:8766173d267f | 2 | |
pro100kot14 | 1:8766173d267f | 3 | Thermistor::Thermistor(AnalogIn inputChanel, double a, double b, double c):input(inputChanel), error(0){ |
pro100kot14 | 1:8766173d267f | 4 | this->a = a; |
pro100kot14 | 1:8766173d267f | 5 | this->b = b; |
pro100kot14 | 1:8766173d267f | 6 | this->c = c; |
pro100kot14 | 1:8766173d267f | 7 | } |
pro100kot14 | 1:8766173d267f | 8 | |
pro100kot14 | 1:8766173d267f | 9 | double Thermistor::getTemperature(){ |
pro100kot14 | 1:8766173d267f | 10 | double temp; |
pro100kot14 | 1:8766173d267f | 11 | double realV; |
pro100kot14 | 1:8766173d267f | 12 | double resistance; |
pro100kot14 | 1:8766173d267f | 13 | //3.3 - ADC maximum |
pro100kot14 | 1:8766173d267f | 14 | realV = input.read()*3.3; |
pro100kot14 | 2:ad2653bcf93f | 15 | resistance = (10000 * 3.3) / realV - 10000; |
pro100kot14 | 1:8766173d267f | 16 | //Considering the error |
pro100kot14 | 1:8766173d267f | 17 | resistance -= error; |
pro100kot14 | 1:8766173d267f | 18 | //Calculations using Steinhart–Hart equation |
pro100kot14 | 1:8766173d267f | 19 | temp = log(resistance); |
pro100kot14 | 1:8766173d267f | 20 | temp = 1/(a+b*temp+c*temp*temp*temp); |
pro100kot14 | 1:8766173d267f | 21 | //Convert from Fahrenheit to Celsius |
pro100kot14 | 1:8766173d267f | 22 | temp -= 273.15; |
pro100kot14 | 1:8766173d267f | 23 | return temp; |
pro100kot14 | 1:8766173d267f | 24 | } |
pro100kot14 | 1:8766173d267f | 25 | |
pro100kot14 | 1:8766173d267f | 26 | void Thermistor::setError(double error){ |
pro100kot14 | 1:8766173d267f | 27 | this->error = error; |
pro100kot14 | 1:8766173d267f | 28 | } |
pro100kot14 | 1:8766173d267f | 29 | |
pro100kot14 | 1:8766173d267f | 30 | double Thermistor::getError(){ |
pro100kot14 | 1:8766173d267f | 31 | return error; |
pro100kot14 | 1:8766173d267f | 32 | } |
pro100kot14 | 1:8766173d267f | 33 | |
pro100kot14 | 1:8766173d267f | 34 | void Thermistor::setCoefficientA(double a){ |
pro100kot14 | 1:8766173d267f | 35 | this->a = a; |
pro100kot14 | 1:8766173d267f | 36 | } |
pro100kot14 | 1:8766173d267f | 37 | |
pro100kot14 | 1:8766173d267f | 38 | void Thermistor::setCoefficientB(double b){ |
pro100kot14 | 1:8766173d267f | 39 | this->b = b; |
pro100kot14 | 1:8766173d267f | 40 | } |
pro100kot14 | 1:8766173d267f | 41 | |
pro100kot14 | 1:8766173d267f | 42 | void Thermistor::setCoefficientC(double c){ |
pro100kot14 | 1:8766173d267f | 43 | this->c = c; |
pro100kot14 | 1:8766173d267f | 44 | } |
pro100kot14 | 1:8766173d267f | 45 | |
pro100kot14 | 1:8766173d267f | 46 | double Thermistor::getCoefficientA(){ |
pro100kot14 | 1:8766173d267f | 47 | return a; |
pro100kot14 | 1:8766173d267f | 48 | } |
pro100kot14 | 1:8766173d267f | 49 | |
pro100kot14 | 1:8766173d267f | 50 | double Thermistor::getCoefficientB(){ |
pro100kot14 | 1:8766173d267f | 51 | return b; |
pro100kot14 | 1:8766173d267f | 52 | } |
pro100kot14 | 1:8766173d267f | 53 | |
pro100kot14 | 1:8766173d267f | 54 | double Thermistor::getCoefficientC(){ |
pro100kot14 | 1:8766173d267f | 55 | return c; |
pro100kot14 | 1:8766173d267f | 56 | } |