-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOutput_relay.h
75 lines (64 loc) · 1.67 KB
/
Output_relay.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
/* Output with relay
Author: Christian Langrock
Date: 2022-August-22
new functions toggleRelays() and
void wind_max_max()
*/
int timeMaxWindSpeed = 0;
long timeMaxMaxWindSpeed = 0;
bool relay = false;
void initRelays() {
pinMode(output_pin_Relay_1, OUTPUT);
pinMode(output_pin_Relay_2, OUTPUT);
// switch off the relays at startup
digitalWrite(output_pin_Relay_1, HIGH);
digitalWrite(output_pin_Relay_2, HIGH);
}
void toggleRelays(){
// toggle relays
if (relay) {
digitalWrite(output_pin_Relay_1, LOW);
digitalWrite(output_pin_Relay_2, LOW);
}
else {
digitalWrite(output_pin_Relay_1, HIGH);
digitalWrite(output_pin_Relay_2, HIGH);
}
}
void wind_max_max(){
relay = true;
timeMaxMaxWindSpeed = Config_timeMaxMaxWindSpeed;
toggleRelays();
}
void wind_max(int wind) {
// task runs every 2s!
// decrase timer for max max wind speed
if (timeMaxMaxWindSpeed >= 1) {
timeMaxMaxWindSpeed = timeMaxMaxWindSpeed - 2;
}
if (wind >= Config_max_max_wind_speed) {
relay = true;
timeMaxMaxWindSpeed = Config_timeMaxMaxWindSpeed;
}
else if (wind >= Config_max_wind_speed) {
if (timeMaxWindSpeed <= Config_timeMaxWindSpeed) {
timeMaxWindSpeed = timeMaxWindSpeed + 2;
}
}
else if (wind <= (Config_max_wind_speed - Config_wind_hyst) && (timeMaxMaxWindSpeed <= 0)) {
if (timeMaxWindSpeed >= 4) {
timeMaxWindSpeed = timeMaxWindSpeed - 4;
}
else if (timeMaxWindSpeed == 2) {
timeMaxWindSpeed = timeMaxWindSpeed - 2;
}
}
if (timeMaxWindSpeed > Config_timeMaxWindSpeed) {
relay = true;
}
else if (timeMaxWindSpeed <= 0) {
relay = false;
}
// toggle relays
toggleRelays();
}