-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogic.h
100 lines (80 loc) · 1.97 KB
/
logic.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
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
#if !defined(LOGIC_H)
#define LOGIC_H
// Project: Automatic plant watering
// Technology: Arduino
// Author: Victor Fisac (git@victorfisac)
#define TIME_24_HOURS 1000*60*60*24
int userMaxHumidityThreshold; // Maximum humidity threshold to stop watering
int userMinHumidityThreshold; // Minimum humidity threshold to start watering
int userTemperatureThreshold; // Minimum temperature threshold to start watering
int userMinHumidityForRain; // Minimum humidity threshold to be considered as rain
int userRainCheck; // Flag to avoid watering in case it has rained in the previous 24 hours
int timesWatered;
int timesRaining;
int isRaining;
int timeCounter;
void InitLogic()
{
userMaxHumidityThreshold = 60;
userMinHumidityThreshold = 15;
userTemperatureThreshold = 20;
userMinHumidityForRain = 90;
userRainCheck = 1;
timesWatered = 0;
timesRaining = 0;
isRaining = 0;
timeCounter = 0;
}
void CheckHumidity()
{
if (isRaining == 1)
{
if (airHumidity <= userMinHumidityForRain)
{
isRaining = 0;
PrintConsole("It has stopped raining");
}
}
else
{
if (airHumidity > userMinHumidityForRain)
{
isRaining = 1;
timesRaining++;
PrintConsole("It is now raining");
}
}
timeCounter += PROGRAM_DELTA_TIME;
if (timeCounter >= TIME_24_HOURS)
{
timeCounter = 0;
timesRaining = 0;
}
}
int CheckRainLogic()
{
int result = 1;
if (userRainCheck == 1)
{
if (timesRaining > 0)
{
result = 0;
}
}
return result;
}
void CheckPumpBehaviour()
{
if (floorHumidity > userMaxHumidityThreshold)
{
SetPump(0);
return;
}
if (airTemperature >= userTemperatureThreshold &&
floorHumidity <= userMinHumidityThreshold &&
CheckRainLogic() == 1)
{
SetPump(1);
}
}
#endif