-
Notifications
You must be signed in to change notification settings - Fork 0
/
tds.h
60 lines (48 loc) · 1.39 KB
/
tds.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//#define DEBUG_TDS
#ifdef DEBUG_TDS
#define D_TDS_PRINT(x) Serial.print(x)
#define D_TDS_PRINTDEC(x) Serial.print(x, DEC)
#define D_TDS_PRINTLN(x) Serial.println(x)
#else
#define D_TDS_PRINT(x)
#define D_TDS_PRINTDEC(x)
#define D_TDS_PRINTLN(x)
#endif
#ifndef TDS_H
#define TDS_H
#include "Arduino.h"
#define ReceivedBufferLength 15
#define TdsFactor 0.5 // tds = ec / 2
class TDS
{
public:
TDS();
~TDS();
void begin();
void update(); //read and calculate
void setPin(int pin);
void setTemperature(float temp); //set the temperature and execute temperature compensation
void setAref(float value); //reference voltage on ADC, default 5.0V on Arduino UNO
void setAdcRange(float range); //1024 for 10bit ADC;4096 for 12bit ADC
float getKvalue();
int getAnalogValue();
float getTdsValue();
float getEcValue();
void calibrate(float calib);
void setKvalue(float Kvalue);
bool getCalibrated();
void setCalibrated(bool state);
private:
int pin;
float aref;
float adcRange;
float temperature;
float kValue; // k value of the probe,you can calibrate in buffer solution ,such as 706.5ppm(1413us/cm)@25^C
int analogValue;
float voltage;
float ecValue; //before temperature compensation
float ecValue25; //after temperature compensation
float tdsValue;
bool calibrated;
};
#endif