-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbrains.ino
288 lines (258 loc) · 8.09 KB
/
brains.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
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
//This is the prototype program.
/*
After push button, pump starts. When desired vacuum reached,
stop pump. Wait for 5 secs(for demonstration purpose), then
start CO2. When desired pressure reached, wait for 5 secs,
then release pressure.
*/
#include <Wire.h>
#include <Adafruit_MPL115A2.h> //sensor library
Adafruit_MPL115A2 mpl115a2;
// SDA connected to A4, SCL connected to A5
// pin 1 - 6: Vdd, GND, SCL, SDA, RST, SDWN
// arduino: 5V, GND, A5, A4, 13, 12
//CONSTANTS
const int Button = 9;
//const int Sensor = A1
const int CO2Relay = 11;//Relay on right, CO2 tied to this pin.
const int VacuumRelay = 10;
const int Relay = 8;//Relay on left
const int RESET =13; //should be connected to 5V for sensor to work
const int SHUTDOWN = 12; //should be connected to 5V for sensor to work
const float VacuumLimit = 80;//Change this to limit.
float PressureLimit;
float NormalPressure = 0;
const int VacuumHoldTime = 5;//seconds
const int CO2HoldTime = 5;//seconds
//VARIABLES
float SensorValue = 0;
int VacuumState = LOW;
int CO2State = LOW;
boolean isWorking = false;
int count = 0;
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
Serial.println("Serial Started...");
pinMode(Button,INPUT);
//pinMode(Sensor,INPUT);
pinMode(CO2Relay,OUTPUT);
pinMode(VacuumRelay,OUTPUT);
pinMode(Relay,OUTPUT);
pinMode(RESET,OUTPUT);
pinMode(SHUTDOWN,OUTPUT);
digitalWrite(Button,LOW);
digitalWrite(CO2Relay,LOW);
digitalWrite(VacuumRelay,LOW);
digitalWrite(Relay,LOW);
//analogWrite(Sensor,0);
digitalWrite(RESET,HIGH);
digitalWrite(SHUTDOWN,HIGH);
delay(1000);
Serial.println("Getting barometric pressure...");
mpl115a2.begin();
NormalPressure = mpl115a2.getPressure();
delay(1000);
Wire.begin();
Serial.print("Pressure: ");
Serial.print(NormalPressure);
Serial.print(" kPa\n");
delay(1000);
Serial.println("Push Button to Start. Push and Hold To Stop.");
}
void loop() {
PressureLimit = NormalPressure;
SensorValue = mpl115a2.getPressure();
if(digitalRead(Button) == HIGH){
isWorking = true;
}
while(isWorking){
Serial.println("Cycle Starts...");
delay(1000);
Serial.println("Pulling Vacuum...");
digitalWrite(VacuumRelay,HIGH);
digitalWrite(Relay,HIGH);
VacuumState = HIGH;
while(VacuumState == HIGH){
SensorValue = mpl115a2.getPressure();
Serial.print("Pressure: ");
Serial.print(SensorValue);
Serial.print(" kPa\n");
delay(1000);
//Stop when button pushed, while working.
if(digitalRead(Button) == HIGH){
isWorking = false;
Serial.println("Cycle Ended by User.");
digitalWrite(VacuumRelay,LOW);
//Add steps to release pressure here.
delay(1000);
Serial.println("Releasing Pressure...");
SensorValue = mpl115a2.getPressure();
while(SensorValue <= (NormalPressure+10)){
digitalWrite(CO2Relay,HIGH);
SensorValue = mpl115a2.getPressure();
Serial.print("Pressure: ");
Serial.print(SensorValue);
Serial.print(" kPa\n");
delay(1000);
if(SensorValue >= (NormalPressure)){
digitalWrite(CO2Relay,LOW);
Serial.println("Done.");
Serial.print("Pressure: ");
Serial.print(SensorValue);
Serial.print(" kPa\n");
delay(5000);
Serial.println("Push Button to Start. Push Again To Stop.");
break;
}
}
break;
}
if(SensorValue <= VacuumLimit){
digitalWrite(VacuumRelay,LOW);
digitalWrite(Relay,LOW);
VacuumState = LOW;
Serial.println("Vacuum Done.");
delay(1000);
count = VacuumHoldTime;
Serial.println("Holding Vacuum...");
while(count > 0){
Serial.println(count);
count--;
delay(1000);
if(digitalRead(Button) == HIGH){
isWorking = false;
Serial.println("Cycle Ended by User.");
//Add steps to release pressure here.
delay(1000);
Serial.println("Releasing Pressure...");
SensorValue = mpl115a2.getPressure();
while(SensorValue <= (NormalPressure+10)){
digitalWrite(CO2Relay,HIGH);
SensorValue = mpl115a2.getPressure();
Serial.print("Pressure: ");
Serial.print(SensorValue);
Serial.print(" kPa\n");
delay(1000);
if(SensorValue >= (NormalPressure)){
digitalWrite(CO2Relay,LOW);
Serial.println("Done.");
Serial.print("Pressure: ");
Serial.print(SensorValue);
Serial.print(" kPa\n");
delay(5000);
Serial.println("Push Button to Start. Push and Hold To Stop.");
break;
}
}
break;
}
}
}
}
if(!isWorking){
break;
}
Serial.println("Injecting CO2...");
digitalWrite(CO2Relay,HIGH);
CO2State = HIGH;
while(CO2State == HIGH){
SensorValue = mpl115a2.getPressure();
Serial.print("Pressure: ");
Serial.print(SensorValue);
Serial.print(" kPa\n");
delay(1000);
if(digitalRead(Button) == HIGH){
isWorking = false;
Serial.println("Cycle Ended by User.");
//Add steps to release pressure here.
delay(1000);
Serial.println("Releasing Pressure...");
SensorValue = mpl115a2.getPressure();
while(SensorValue <= (NormalPressure+10)){
digitalWrite(CO2Relay,HIGH);
SensorValue = mpl115a2.getPressure();
Serial.print("Pressure: ");
Serial.print(SensorValue);
Serial.print(" kPa\n");
delay(1000);
if(SensorValue >= (NormalPressure)){
digitalWrite(CO2Relay,LOW);
Serial.println("Done.");
Serial.print("Pressure: ");
Serial.print(SensorValue);
Serial.print(" kPa\n");
delay(5000);
Serial.println("Push Button to Start. Push and Hold To Stop.");
break;
}
}
break;
}
if(SensorValue >= (PressureLimit)){
digitalWrite(CO2Relay,LOW);
CO2State = LOW;
Serial.println("CO2 Injecting Done.");
count = CO2HoldTime;
delay(1000);
Serial.println("Holding CO2 Pressure...");
while(count > 0){
Serial.println(count);
count--;
if(digitalRead(Button) == HIGH){
isWorking = false;
Serial.println("Cycle Ended by User.");
//Add steps to release pressure here.
delay(1000);
Serial.println("Releasing Pressure...");
SensorValue = mpl115a2.getPressure();
while(SensorValue <= (NormalPressure+10)){
digitalWrite(CO2Relay,HIGH);
SensorValue = mpl115a2.getPressure();
Serial.print("Pressure: ");
Serial.print(SensorValue);
Serial.print(" kPa\n");
delay(1000);
if(SensorValue >= (NormalPressure)){
digitalWrite(CO2Relay,LOW);
Serial.println("Done.");
Serial.print("Pressure: ");
Serial.print(SensorValue);
Serial.print(" kPa\n");
delay(5000);
Serial.println("Push Button to Start. Push and Hold To Stop.");
break;
}
}
break;
}
delay(1000);
}
}
}
if(!isWorking){
break;
}
/*
Serial.println("Releaseing Pressure...");
SensorValue = mpl115a2.getPressure();
while(SensorValue >= (NormalPressure+10)){
digitalWrite(Relay,HIGH);
SensorValue = mpl115a2.getPressure();
if(SensorValue <= (NormalPressure + 10) || SensorValue >= (NormalPressure - 10)){
digitalWrite(Relay,LOW);
Serial.println("Done.");
isWorking = false;
break;
}
}
*/
Serial.println("Done.");
Serial.print("Pressure: ");
Serial.print(SensorValue);
Serial.print(" kPa\n");
isWorking = false;
delay(5000);
Serial.println("Push Button to Start. Push and Hold To Stop.");
}
}