-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
104 lines (91 loc) · 2.36 KB
/
main.cpp
File metadata and controls
104 lines (91 loc) · 2.36 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
Modified on Nov 28, 2020
Modified by MehranMaleki from Arduino Examples
Home
*/
#include "Board.h"
#include "Display.h"
#include "Humidity.h"
#include "MyServo.h"
#include "PhSensor.h"
#include "Temperature.h"
#include "Turbidity.h"
#include "WaterLevel.h"
#include "Wifizinho.h"
#include "utils.h"
Wifizinho wifizinho;
PhSensor phSensor;
Humidity humidity;
Turbidity turbidity;
Temperature temperature;
MyServo myServo;
WaterLevel waterLevel;
Board board;
int selectedSensor = HUMIDITY_SENSOR;
int lastFeeding = 0;
long feedInterval = 30000;
void setup() {
Serial.begin(9600);
pinMode(JOY_VERT, INPUT);
pinMode(BUTTON_LEFT_PIN, INPUT_PULLUP);
pinMode(S0, OUTPUT);
digitalWrite(S0, LOW);
board.init();
wifizinho.connect();
temperature.begin();
myServo.init();
delay(100);
}
static unsigned long now;
static unsigned long lastUpdate = 0;
void loop() {
int buttonState = board.getButtonState();
Sensor selectedSensor = board.getSelectedSensor();
waterLevel.update();
if (buttonState == LOW || (now - lastFeeding >= feedInterval)) {
lastFeeding = now;
myServo.dispense();
}
now = millis();
if (now - lastUpdate > 2000) {
float value = 0.0;
lastUpdate = now;
String path;
switch (selectedSensor) {
case PH_SENSOR:
digitalWrite(S0, HIGH);
value = phSensor.getPh();
board.print("PH:");
if (value != -1) board.print(String(value));
phSensor.print();
path = "/pH";
break;
case HUMIDITY_SENSOR:
digitalWrite(S0, LOW);
value = humidity.getAnalog();
board.print("Humidity:");
if (value != -1) board.print(String(value));
humidity.print();
path = "/humidity";
break;
case TURBIDITY_SENSOR:
value = turbidity.getDigital();
board.print("Turbidity:");
board.print(String(value));
path = "/turbidity";
turbidity.print();
break;
case TEMPERATURE_SENSOR:
value = temperature.getTemperature();
board.print("Temperature:");
board.print(String(value) + " C");
Serial.print("Temperature= ");
Serial.println(String(value) + " C");
path = "/temperature";
break;
}
String timestamp = String(millis());
wifizinho.sendData(timestamp, int(value), path);
lastUpdate = millis();
}
}