Conner Hensley / phread

Dependents:   595_Project2_Hydro

Files at this revision

API Documentation at this revision

Comitter:
thecreid1
Date:
Wed May 06 14:56:32 2020 +0000
Commit message:
Firmware;

Changed in this revision

phread.cpp Show annotated file Show diff for this revision Revisions of this file
phread.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 973b5707f517 phread.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/phread.cpp	Wed May 06 14:56:32 2020 +0000
@@ -0,0 +1,26 @@
+#include "phread.h"
+
+PHread::PHread (PinName data_pin) : 
+    _datapin (data_pin)
+{}
+
+float PHread::get_pH(){
+  float mv_voltage = 0;
+  float ph_val=0;
+
+    
+  for(int i=0;i<10;i++)       //Get 10 sample value from the sensor for smooth the value
+  { 
+    mv_voltage += (_datapin.read() * 3.1); 
+    wait_ms(10);
+  }
+  mv_voltage /= 10;
+  
+  //formuala to convert from voltage signal to ph
+  //from atlasScientific
+  ph_val = (-5.6548 * mv_voltage) + 15.509; 
+  
+  
+  
+    return ph_val;
+}
\ No newline at end of file
diff -r 000000000000 -r 973b5707f517 phread.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/phread.h	Wed May 06 14:56:32 2020 +0000
@@ -0,0 +1,21 @@
+#ifndef _phread_H_
+#define _phread_H_
+
+#include "mbed.h"
+
+class PHread {
+    public:
+        PHread (PinName data_pin);
+
+        /** Reads the pH
+        * 
+        * @returns pH
+        */
+        float get_pH();
+
+    private:
+        AnalogIn _datapin;
+
+};
+
+#endif
\ No newline at end of file