-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchecksensor.h
72 lines (55 loc) · 1.26 KB
/
checksensor.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
#include "./button.h";
#include <OneWire.h>
#include <DallasTemperature.h>
#include <AverageValue.h>
#include "./config.h"
int wrn = false;
int ovht = false;
int printed = false;
int trig = false;
float maxT = 0;
float minT = 50;
OneWire oneWire(TEMP_PORT);
DallasTemperature sensors(&oneWire);
const long MAX_VALUES_NUM = 40;
//40 measurements
AverageValue<float> averageValue(MAX_VALUES_NUM);
void checkSensors() {
sensors.requestTemperatures();
float curr;
if(USE_F) {
curr = sensors.getTempFByIndex(0);
} else {
curr = sensors.getTempCByIndex(0);
}
averageValue.push(curr);
if (curr > maxT) {
maxT = curr;
}
if (curr < minT) {
minT = curr;
}
if (curr > TEMP_WARN) {
if (curr > TEMP_OVHT) {
if(!trig) {
ledState = HIGH;
digitalWrite(FAN_PORT, HIGH);
trig = true; //avoid this turning the fan on again if you manually turn it off
}
ovht = true;
} else {
wrn = true;
}
}
if (ovht && curr < TEMP_WARN) {
wrn = false;
if (ovht) {
ledState = LOW;
digitalWrite(FAN_PORT, LOW);
ovht = false;
trig = false;
}
}else if(wrn && curr < TEMP_WARN) {
wrn = false;
}
}