j

Revision:
1:dc9389ccc09d
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/thermistor/thermistor.cpp	Wed Sep 11 12:15:15 2019 +0000
@@ -0,0 +1,34 @@
+#include "mbed.h"
+#include "thermistor.h"
+
+Thermistor::Thermistor(AnalogIn *aIn)
+{
+    _aIn = aIn;
+}
+
+double Thermistor::getTemperature()
+{
+    this->getResistance();
+    if(this->_resistance > RES_25C){
+        this->_temperature = (25.0 - ((this->_resistance - RES_25C) / RES_DIFF_PER_C));
+    } else if(this->_resistance < RES_25C){
+        this->_temperature = (25.0 + ((RES_25C - this->_resistance) / RES_DIFF_PER_C));
+    } else {
+        this->_temperature = 25.0;
+    }
+    printf("resistance : %f\n", _resistance);
+    return this->_temperature;
+}
+
+void Thermistor::getResistance()
+{
+    double sum = 0.0;
+    uint16_t adc_data[SAMPLE_COUNT], average;
+    int i = 0;
+    while(i < SAMPLE_COUNT) {
+        adc_data[i] = ((_aIn->read_u16() >> 4) & 0x0FFF);
+        sum += adc_data[i++];
+    }
+    average = sum / SAMPLE_COUNT;
+    this->_resistance = (((BALANCE_RES_S * 0x0FFF) / average)) - BALANCE_RES_S;
+}
\ No newline at end of file