-
Notifications
You must be signed in to change notification settings - Fork 1
/
PhProbe.cpp
68 lines (61 loc) · 1.48 KB
/
PhProbe.cpp
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
59
60
61
62
63
64
65
66
67
68
#include<Arduino.h>
#include "PhProbe.h"
PhProbe::PhProbe(int r, int t) {
rx = r;
tx = t;
received_from_sensor = 0;
tempPH = 7.00;
pH = 7.00;
}
void PhProbe::begin(int baud_rate) {
sensor = new SoftwareSerial(rx, tx);
sensor->begin(9600);
}
int PhProbe::available() {
return sensor->available();
}
void PhProbe::read() {
received_from_sensor = sensor->readBytesUntil(13, data, 20);
data[received_from_sensor] = 0;
Serial.println(data);
tempPH = atof(data);
if (tempPH > 0) {
pH = tempPH;
}
}
void PhProbe::command(String command, String parameter) {
sensor->listen();
if (command == "CALI") {
if (parameter == "L") {
sensor->print("Cal,low,4.00\r");
} else if (parameter == "M") {
sensor->print("Cal,mid,7.00\r");
} else if (parameter == "H") {
sensor->print("Cal,high,10.00\r");
} else if (parameter == "?") {
sensor->print("Cal,?\r");
} else {
Serial.println("ERPARA");
}
} else if (command == "LEDS") {
if (parameter == "0") {
sensor->print("L,0\r");
} else if (parameter == "1") {
sensor->print("L,1\r");
} else {
Serial.println("ERPARA");
}
} else if (command == "READ") {
sensor->print("R,0\r");
} else if (command == "MODE") {
if (parameter == "0") {
sensor->print("C,0\r");
} else if (parameter == "1") {
sensor->print("C,1\r");
} else {
Serial.println("ERPARA");
}
} else {
Serial.println("ERCOMM");
}
}