-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathValve.h
47 lines (37 loc) · 861 Bytes
/
Valve.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
/**
* Pressure.h
* Calculates and stores the key pressure values of the breathing cycle.
*/
#ifndef Valve_h
#define Valve_h
#include "Arduino.h"
#include "Constants.h"
enum ValveState {
CLOSED, // 0
OPEN // 1
};
class Valve {
public:
Valve(int pin, bool normallyOpen):
valve_pin_(pin),
is_normally_open_(normallyOpen),
state_(normallyOpen ? OPEN:CLOSED) {}
void open() {
state_ = OPEN;
is_normally_open_ ? digitalWrite(valve_pin_, LOW) : digitalWrite(valve_pin_, HIGH);
}
void close() {
state_ = CLOSED;
is_normally_open_ ? digitalWrite(valve_pin_, HIGH) : digitalWrite(valve_pin_, LOW);
}
ValveState get() const { return state_; }
private:
int valve_pin_;
bool is_normally_open_;
ValveState state_;
};
// Valves
extern Valve oxygenValve;
extern Valve airValve;
extern Valve expValve;
#endif