-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path18b20_temp.ino
144 lines (112 loc) · 3.67 KB
/
18b20_temp.ino
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
//
// Dallas Temperature Sensors
//
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 40
// Setup a oneWire instance to communicate with any OneWire devices
// (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
DeviceAddress tempDeviceAddress;
int resolution = 12;
unsigned long lastTempRequest = 0;
int delayInMillis = 0;
//
// SETUP
//
void temp_setup(void)
{
sensors.begin();
// Adrese definirane u main!
// todo: (odvoji u env)
//sensors.getAddress(tempDeviceAddress, 0);
sensors.setResolution(sonda_odlaz_topla_voda, resolution);
sensors.setResolution(sonda_pec, resolution);
sensors.setResolution(sonda_solar, resolution);
sensors.setResolution(sonda_spremnik, resolution);
sensors.setResolution(sonda_povrat_hladne_vode, resolution);
sensors.setWaitForConversion(false);
sensors.requestTemperatures();
delayInMillis = 750 / (1 << (12 - resolution));
lastTempRequest = millis();
}
// Temperature sensors loop.
void temperature_sensors(void)
{
if (millis() - lastTempRequest >= delayInMillis) // waited long enough??
{
//Serial.print(" Temperature: ");
temp_odlaz_topla_voda = sensors.getTempC(sonda_odlaz_topla_voda);
if (temp_odlaz_topla_voda == -127.0) {
temp_odlaz_topla_voda = temp_odlaz_topla_voda_h;
temp_odlaz_topla_voda_ctu = temp_odlaz_topla_voda_ctu + 1;
if (temp_odlaz_topla_voda_ctu == 10) {
temp_odlaz_topla_voda = -127.0;
}
} else {
temp_odlaz_topla_voda_h = temp_odlaz_topla_voda;
temp_odlaz_topla_voda_ctu = 0;
}
//
temp_pec = sensors.getTempC(sonda_pec);
if (temp_pec == -127.0) {
temp_pec = temp_pec_h;
temp_pec_ctu = temp_pec_ctu + 1;
if (temp_pec_ctu == 10) {
temp_pec = -127.0;
}
} else {
temp_pec_h = temp_pec;
temp_pec_ctu = 0;
}
//
temp_solar = sensors.getTempC(sonda_solar);
if (temp_solar == -127.0) {
temp_solar = temp_solar_h;
temp_solar_ctu = temp_solar_ctu + 1;
if (temp_solar_ctu == 10) {
temp_odlaz_topla_voda = -127.0;
}
} else {
temp_solar_h = temp_solar;
temp_solar_ctu = 0;
}
//
temp_spremnik = sensors.getTempC(sonda_spremnik );
if (temp_spremnik == -127.0) {
temp_spremnik = temp_spremnik_h;
temp_spremnik_ctu = temp_spremnik_ctu + 1;
if (temp_spremnik_ctu == 10) {
temp_odlaz_topla_voda = -127.0;
}
} else {
temp_spremnik_h = temp_spremnik;
temp_spremnik_ctu = 0;
}
//
temp_povrat_hladne_vode = sensors.getTempC(sonda_povrat_hladne_vode);
if (temp_povrat_hladne_vode == -127.0) {
temp_povrat_hladne_vode = temp_povrat_hladne_vode_h;
temp_povrat_hladne_vode_ctu = temp_povrat_hladne_vode_ctu + 1;
if (temp_povrat_hladne_vode_ctu == 10) {
temp_odlaz_topla_voda = -127.0;
}
} else {
temp_povrat_hladne_vode_h = temp_povrat_hladne_vode;
temp_povrat_hladne_vode_ctu = 0;
}
//sensors.setResolution(tempDeviceAddress, resolution);
sensors.requestTemperatures();
delayInMillis = 750 / (1 << (12 - resolution));
delayInMillis = delayInMillis + 500;
Serial.println(temp_odlaz_topla_voda);
Serial.println(temp_pec);
Serial.println(temp_solar);
Serial.println(temp_spremnik);
Serial.println(temp_povrat_hladne_vode);
lastTempRequest = millis();
}
}