This repository was archived by the owner on Mar 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupdateSensors.ino
40 lines (28 loc) · 1.58 KB
/
updateSensors.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
void updateSensors() {
unsigned char currentFloatSensorState = digitalRead(FloatSensor);
unsigned char currentHighLevelState = !digitalRead(HighLevelSw);
inletPres = digitalRead(PresSw);
//checks float sensor state, only register a change in the sensor state being low if it has been so for at least 3 second
if (currentFloatSensorState == HIGH) { //if float sensor is high, register it immediately
FloatSensorState = HIGH;
} else if (currentFloatSensorState == LOW && lastFloatSensorState == HIGH) { //float sensor reading changed to low, record time of change
lastFloatSensorChangeTime = millis();
} else if (currentFloatSensorState == LOW && lastFloatSensorState == LOW){ //float sensor reading low consecutively
if (millis() - lastFloatSensorChangeTime > 3000) { //float reading stays low for at least 1 second
FloatSensorState = LOW; //updates the global variable for float sensor
}
}
lastFloatSensorState = currentFloatSensorState;
//checks high level sensor, only register a change if it has been so for at least 1 second
if (lastHighLevelState != currentHighLevelState) { //high level sensor reading changed
lastHighLevelChangeTime = millis();
} else { //high level sensor reading remains the same
if (millis() - lastHighLevelChangeTime > 1000) {
HighLevelState = currentHighLevelState; //updates the global variable for high level sensor
}
}
lastHighLevelState = currentHighLevelState;
if (HighLevelState == HIGH) { //if high level switch register high level twice in a row
errorFlag = true;
}
}