Scientific task box V1

Dependencies:   HX711 DS1820

Dependents:   Scientific_RTOS Scientific_RTOS

Revision:
2:f8120bb54b69
Parent:
0:01deb85101c9
Child:
3:442e7d2ab496
--- a/BOX.cpp	Mon May 13 13:56:45 2019 +0000
+++ b/BOX.cpp	Mon Jun 10 12:49:50 2019 +0000
@@ -1,6 +1,6 @@
 #include "BOX.h"
 
-BOX::BOX (PinName pinCLK_HX711, PinName pinDAT_HX711, PinName pin_temp, PinName pin_cond, int HX711_coefficent):therm(pin_temp, DS18B20::RES_12_BIT),balance(pinDAT_HX711, pinCLK_HX711)
+BOX::BOX (PinName pinCLK_HX711, PinName pinDAT_HX711, PinName pin_temp, PinName pin_cond, int HX711_coefficent):ds1820(pin_temp),balance(pinDAT_HX711, pinCLK_HX711)
 {
   _pinCLK = pinCLK_HX711;
   _pinDAT = pinDAT_HX711;
@@ -11,20 +11,50 @@
   
 }
 
-//BOX::~BOX(){}
+
+
+
+
+BOX::~BOX(){}
+
+
+void BOX::initialize(){
+    
+    check=ds1820.begin();
+    
+    }
 
 float BOX::get_temp()
 {
-  float temperature;
-  _tmp = 0;
-  for (int i = 0; i < 20; i++)
-  {
-    _tmp = therm.GetTemperature();
-    temperature = temperature + _tmp;
-  }
-  return temperature / 20;
+  int result=0;
+  float temp=0;
+                    ds1820.startConversion();   // start temperature conversion from analog to digital
+            wait(1.0);                  // let DS1820 complete the temperature conversion
+            result = ds1820.read(temp); // read temperature from DS1820 and perform cyclic redundancy check (CRC)
+            switch (result) {
+                case 0:                 // no errors -> 'temp' contains the value of measured temperature
+                  
+                    break;
+
+                case 1:                 // no sensor present -> 'temp' was not updated
+                    printf("no sensor present\n\r");
+                    break;
+
+                case 2:                 // CRC error -> 'temp' was not updated
+                    printf("CRC error\r\n");
+                    
+                default:
+                break;
+            
+
+        }
+
+
+return temp;
 }
 
+
+
 int BOX::get_resistance()
 {
   AnalogIn cond_value(_pincond);                // reads voltage on the conductimeter pin.