-
Notifications
You must be signed in to change notification settings - Fork 0
/
PressureControlSoftware.ino
47 lines (39 loc) · 1.04 KB
/
PressureControlSoftware.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
#include "Parameters.h"
#include "Reader.h"
#include "Display.h"
#include "Valve.h"
// #define SERIAL_DEBUG 0
void setup() {
#ifdef SERIAL_DEBUG
Serial.begin(9600);
Serial.println("Starting...");
#endif
Display::init();
Valve::init();
pinMode(13, OUTPUT);
}
void loop() {
digitalWrite(13, !digitalRead(13)); // activity indicator
float targetPsi = getTargetPressureDelta();
float measuredPsi = getPressureMeasuredDelta();
float offPsi = targetPsi - measuredPsi;
float valveOpening = Valve::getOpening();
#ifndef SERIAL_DEBUG
Display::showPressureSelection(measuredPsi, targetPsi);
Display::showValveOpening(valveOpening, 0.f);
Display::submit();
#endif
#ifdef SERIAL_DEBUG
Serial.print("Off by: ");
Serial.print(offPsi, 2);
Serial.println(" psi");
#endif
// motor movement
if (abs(offPsi) > toleratedPsiDelta) {
Valve::move(offPsi < 0); // open or close depending on inequality
}
else {
Valve::stop();
}
Valve::setSlow(abs(offPsi) < lowSpeedPsiDelta); // control speed
}