-
Notifications
You must be signed in to change notification settings - Fork 0
/
pneumatic_system.h
116 lines (91 loc) · 2.14 KB
/
pneumatic_system.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
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
class PneumaticSystem
{
public:
PneumaticSystem();
void initialize(const int pump_pin, const int k1, const int k2, const int k3);
void terminate();
void activate_pump();
void deactivate_pump();
void activate_relay(const int relay_id);
void deactivate_relay(const int relay_id);
void deactivate_all();
void activate_all();
private:
int _k1, _k2, _k3;
int _pump_pin;
};
PneumaticSystem::PneumaticSystem()
{
}
void PneumaticSystem::initialize(const int pump_pin, const int k1, const int k2, const int k3)
{
_k1 = k1;
_k2 = k2;
_k3 = k3;
_pump_pin = pump_pin;
pinMode(_k1, OUTPUT);
digitalWrite(_k1, HIGH); // turns it OFF
pinMode(_k2, OUTPUT);
digitalWrite(_k2, HIGH); // turns it OFF
pinMode(_k3, OUTPUT);
digitalWrite(_k3, HIGH); // turns it OFF
pinMode(_pump_pin, OUTPUT);
digitalWrite(_pump_pin, HIGH); // turns it OFF
deactivate_all();
}
void PneumaticSystem::terminate()
{
deactivate_all();
}
void PneumaticSystem::activate_pump()
{
digitalWrite(_pump_pin, LOW); // turns it ON
}
void PneumaticSystem::deactivate_pump()
{
digitalWrite(_pump_pin, HIGH); // turns it ON
}
void PneumaticSystem::activate_relay(const int relay_id)
{
switch(relay_id)
{
case 0:
digitalWrite(_k1, LOW); // turns it ON
break;
case 1:
digitalWrite(_k2, LOW); // turns it ON
break;
case 2:
digitalWrite(_k3, LOW); // turns it ON
break;
}
}
void PneumaticSystem::deactivate_relay(const int relay_id)
{
switch(relay_id)
{
case 0:
digitalWrite(_k1, HIGH); // turns it OFF
break;
case 1:
digitalWrite(_k2, HIGH); // turns it OFF
break;
case 2:
digitalWrite(_k3, HIGH); // turns it OFF
break;
}
}
void PneumaticSystem::deactivate_all()
{
digitalWrite(_k1, HIGH); // turns it OFF
digitalWrite(_k2, HIGH); // turns it OFF
digitalWrite(_k3, HIGH); // turns it OFF
digitalWrite(_pump_pin, HIGH); // turns it OFF
}
void PneumaticSystem::activate_all()
{
digitalWrite(_k1, LOW); // turns it ON
digitalWrite(_k2, LOW); // turns it ON
digitalWrite(_k3, LOW); // turns it ON
digitalWrite(_pump_pin, LOW); // turns it ON
}