-
Notifications
You must be signed in to change notification settings - Fork 3
/
TempFeedback.ino
377 lines (340 loc) · 9.5 KB
/
TempFeedback.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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
float TEMP_REF_POT = 20.0;
int IT_0;
/////////////////// TEMP CODE ABOVE
// MAX and MIN Temps for SAFETY
float MAX_TEMP = 35.0;
float MIN_TEMP = 10.0;
int PERIOD = 100;
/*
Thermistors:
------------
Thumb:1
Index finger:2
Middle finger:3
Ring finger:4
Pinky:5
Palm:6
Peltier plate:7
*/
int Therm_1 = 8;
int Therm_2 = 9;
int Therm_3 = 10;
int Therm_4 = 11;
int Therm_5 = 12;
int Therm_6 = 13;
int Therm_7 = 14;
int Therm_8 = 15;
int IT_1;
int IT_2;
int IT_3;
int IT_4;
int IT_5;
int IT_6;
int IT_7;
int IT_8;
// This is the Temperature Values from the Thermistors
float T1, T2, T3, T4, T5, T6, T7, T8, T_AVG;
// This is the Reference Temperature (Numbers match the thermistor value
float RT1, RT2, RT3, RT4, RT5, RT6, RT_AVG;
/*
Heating pads:
-------------
Thumb:G
Index finger:F
Middle finger:E
Ring finger:B
Pinky:A
Palm:D
*/
int CoolerPin_C = 22;
int HeaterPin_A = 26;
int HeaterPin_BE = 30;//SAME AS A_TEMP
int HeaterPin_D = 34;
//int HeaterPin_E = 34; //SAME AS _TEMP
int HeaterPin_F = 38;
int HeaterPin_G = 42;
int ON_TIME = 0;
int OFF_TIME = PERIOD;
int HTR_ON_TIME_A = 0;
int HTR_OFF_TIME_A = PERIOD;
int HTR_ON_TIME_BE = 0; // NOT CURRENTLY USED
int HTR_ON_TIME_D = 0;
//int HTR_ON_TIME_E = 0;
int HTR_ON_TIME_F = 0;
int HTR_ON_TIME_G = 0;
int LOOPER = 0;
int DEBUG_TEMP = 1;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(CoolerPin_C, OUTPUT); // sets the digital pin as output
pinMode(HeaterPin_A, OUTPUT); // sets the digital pin as output
pinMode(HeaterPin_BE, OUTPUT); // sets the digital pin as output
pinMode(HeaterPin_D, OUTPUT); // sets the digital pin as output
//pinMode(HeaterPin_E, OUTPUT); // sets the digital pin as output
pinMode(HeaterPin_F, OUTPUT); // sets the digital pin as output
pinMode(HeaterPin_G, OUTPUT); // sets the digital pin as output
}
void loop() {
IT_0 = analogRead(0);
TEMP_REF_POT = ((IT_0/51.6)+15); // (0-1022)/500+18
/////////////////////// TEMP CODE ABOVE
// put your main code here, to run repeatedly:
// Note, High means (heater/cooler) = OFF, Low means (heater/cooler) = ON
// Start of program: Read Temperatures
IT_1 = analogRead(Therm_1);
IT_2 = analogRead(Therm_2);
IT_3 = analogRead(Therm_3);
IT_4 = analogRead(Therm_4);
IT_5 = analogRead(Therm_5);
IT_6 = analogRead(Therm_6);
IT_7 = analogRead(Therm_7);
IT_8 = analogRead(Therm_8);
if(DEBUG_TEMP == 0){
Serial.print("TEMP_REF: ");
Serial.print(IT_0);
Serial.print(" 1: ");
Serial.print(IT_1);
Serial.print(" 2: ");
Serial.print(IT_2);
Serial.print(" 3: ");
Serial.print(IT_3);
Serial.print(" 4: ");
Serial.print(IT_4);
Serial.print(" 5: ");
Serial.print(IT_5);
Serial.print(" 6: ");
Serial.print(IT_6);
Serial.print(" 7: ");
Serial.print(IT_7);
Serial.print(" 8: ");
Serial.print(IT_8);
Serial.println("");
}
// This is used to convert from voltage values to Temperature values in *C
T1 = (0.1319*IT_1 -40);
T2 = (0.1319*IT_2 -40);
T3 = (0.1319*IT_3 -40);
T4 = (0.1319*IT_4 -40);
T5 = (0.1319*IT_5 -40);
T6 = (0.1319*IT_6 -40);
T7 = (0.1319*IT_7 -40);
T8 = (0.1319*IT_8 -40);
if(DEBUG_TEMP == 1){
Serial.print("REF_POT: ");
Serial.print(TEMP_REF_POT);
Serial.print(" 1: ");
Serial.print(T1);
Serial.print(" 2: ");
Serial.print(T2);
Serial.print(" 3: ");
Serial.print(T3);
Serial.print(" 4: ");
Serial.print(T4);
Serial.print(" 5: ");
Serial.print(T5);
Serial.print(" 6: ");
Serial.print(T6);
Serial.print(" 7: ");
Serial.print(T7);
Serial.print(" 8: ");
Serial.print(T8);
Serial.println("");
}
/////////////////////// TEMP CODE BELOW
RT1 = TEMP_REF_POT;
RT2 = TEMP_REF_POT;
RT3 = TEMP_REF_POT;
RT4 = TEMP_REF_POT;
RT5 = TEMP_REF_POT;
RT6 = TEMP_REF_POT;
/////////////////////// TEMP CODE ABOVE
////////////////////////////////////////////////////////////////////
// This is used as a safety feature, ensure that max temperature limits
if((MAX_TEMP < RT1) || (MIN_TEMP > RT1)){
RT1 = (MAX_TEMP + MIN_TEMP)/2.0; // Set to Average
}
if((MAX_TEMP < RT2) || (MIN_TEMP > RT2)){
RT2 = (MAX_TEMP + MIN_TEMP)/2.0; // Set to Average
}
if((MAX_TEMP < RT3) || (MIN_TEMP > RT3)){
RT3 = (MAX_TEMP + MIN_TEMP)/2.0; // Set to Average
}
if((MAX_TEMP < RT4) || (MIN_TEMP > RT4)){
RT4 = (MAX_TEMP + MIN_TEMP)/2.0; // Set to Average
}
if((MAX_TEMP < RT5) || (MIN_TEMP > RT5)){
RT5 = (MAX_TEMP + MIN_TEMP)/2.0; // Set to Average
}
if((MAX_TEMP < RT6) || (MIN_TEMP > RT6)){
RT6 = (MAX_TEMP + MIN_TEMP)/2.0; // Set to Average
}
// This is the reference temperature average
RT_AVG = ((RT1 + RT2 + RT3 + RT4 + RT5 + RT6)/6.0);
T_AVG = ((T1 + T2 + T3 + T4 + T5 + T6 + T7 + T8)/8.0);
////////////////////////////////////////////////////////////////////
// PALM - T7(Plate)
// Temp Controller Colder
if (RT_AVG > T7) {
ON_TIME = ON_TIME - 25;
} else
if ((RT_AVG < T7) || (RT_AVG < T_AVG)) {
ON_TIME = ON_TIME + 10;
}
OFF_TIME = (PERIOD - ON_TIME);
// Saturator Limit
if (ON_TIME >= PERIOD) {
ON_TIME = PERIOD;
} else if (ON_TIME <= 0) {
ON_TIME = 0;
}
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// PINKY(A) - T5
// Temp Controller - HOTER A
if (RT5 > T5) {
HTR_ON_TIME_A = HTR_ON_TIME_A + 10;
} else
if (RT5 < T5) {
HTR_ON_TIME_A = HTR_ON_TIME_A - 50;
}
// Saturator Limit
if (HTR_ON_TIME_A >= PERIOD) {
HTR_ON_TIME_A = PERIOD;
} else if (HTR_ON_TIME_A <= 0) {
HTR_ON_TIME_A = 0;
}
////////////////////////////////////////////////////////////////////
// THUMB(G) - T1
// Temp Controller - HOTER G
if (RT1 > T1) {
HTR_ON_TIME_G = HTR_ON_TIME_G + 10;
} else
if (RT1 < T1) {
HTR_ON_TIME_G = HTR_ON_TIME_G - 50;
}
// Saturator Limit
if (HTR_ON_TIME_G >= PERIOD) {
HTR_ON_TIME_G = PERIOD;
} else if (HTR_ON_TIME_G <= 0) {
HTR_ON_TIME_G = 0;
}
////////////////////////////////////////////////////////////////////
// INDEX(F) - T2
// Temp Controller - HOTER F
if (RT2 > T2) {
HTR_ON_TIME_F = HTR_ON_TIME_F + 10;
} else
if (RT2 < T2) {
HTR_ON_TIME_F = HTR_ON_TIME_F - 50;
}
// Saturator Limit
if (HTR_ON_TIME_F >= PERIOD) {
HTR_ON_TIME_F = PERIOD;
} else if (HTR_ON_TIME_F <= 0) {
HTR_ON_TIME_F = 0;
}
////////////////////////////////////////////////////////////////////
// PALM(D) - T6
// Temp Controller - HOTER d
if (RT6 > T6) {
HTR_ON_TIME_D = HTR_ON_TIME_D + 10;
} else
if (RT6 < T6) {
HTR_ON_TIME_D = HTR_ON_TIME_D - 50;
}
// Saturator Limit
if (HTR_ON_TIME_D >= PERIOD) {
HTR_ON_TIME_D = PERIOD;
} else if (HTR_ON_TIME_D <= 0) {
HTR_ON_TIME_D = 0;
}
////////////////////////////////////////////////////////////////////
// RING+MIDDLE(BE) - T3+T4
// Temp Controller - HOTER BE
if ((RT3 > T3) || (RT4 > T4)) {
HTR_ON_TIME_BE = HTR_ON_TIME_BE + 10;
} else
if ((RT3 < T3) || (RT4 < T4)) {
HTR_ON_TIME_BE = HTR_ON_TIME_BE - 50;
}
// Saturator Limit
if (HTR_ON_TIME_BE >= PERIOD) {
HTR_ON_TIME_BE = PERIOD;
} else if (HTR_ON_TIME_BE <= 0) {
HTR_ON_TIME_BE = 0;
}
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// HEATER OR COOLER ONLY _ NOT BOTH
if ( RT_AVG > T_AVG) {
ON_TIME = 0;
}else {
HTR_ON_TIME_A = 0;
HTR_ON_TIME_BE = 0;
HTR_ON_TIME_D = 0;
//HTR_ON_TIME_E = 0;
HTR_ON_TIME_F = 0;
HTR_ON_TIME_G = 0;
}
////////////////////////////////////////////////////////////////////
// This is to turn on or off each of the specific elements at a various level
if(LOOPER < ON_TIME){
digitalWrite(CoolerPin_C, LOW); // COOLER ON
}
else {
digitalWrite(CoolerPin_C, HIGH); // COOLER OFF
}
if(LOOPER < HTR_ON_TIME_A){
digitalWrite(HeaterPin_A, LOW); // HEATER A ON
}
else {
digitalWrite(HeaterPin_A, HIGH); // HEATER A OFF
}
if(LOOPER < HTR_ON_TIME_A){
digitalWrite(HeaterPin_BE, LOW); // HEATER A ON
}
else {
digitalWrite(HeaterPin_BE, HIGH); // HEATER A OFF
}
if(LOOPER < HTR_ON_TIME_D){
digitalWrite(HeaterPin_D, LOW); // HEATER A ON
}
else {
digitalWrite(HeaterPin_D, HIGH); // HEATER A OFF
}
///if(LOOPER < HTR_ON_TIME_E){
/// digitalWrite(HeaterPin_E, LOW); // HEATER A ON
/// }
///else {
/// digitalWrite(HeaterPin_E, HIGH); // HEATER A OFF
/// }
if(LOOPER < HTR_ON_TIME_F){
digitalWrite(HeaterPin_F, LOW); // HEATER A ON
}
else {
digitalWrite(HeaterPin_F, HIGH); // HEATER A OFF
}
if(LOOPER < HTR_ON_TIME_G){
digitalWrite(HeaterPin_G, LOW); // HEATER A ON
}
else {
digitalWrite(HeaterPin_G, HIGH); // HEATER A OFF
}
/////////////////////// TEMP CODE BELOW
// TO PRVENT FROM TURNING ON, WILL NEED TO DELETE
// digitalWrite(CoolerPin_C, HIGH);
// digitalWrite(HeaterPin_A, HIGH);
// digitalWrite(HeaterPin_BE, HIGH);
// digitalWrite(HeaterPin_D, HIGH);
// ////// //digitalWrite(HeaterPin_E, HIGH); // NOT CURRENTLY USED
// digitalWrite(HeaterPin_F, HIGH);
// digitalWrite(HeaterPin_G, HIGH);
/////////////////////// TEMP CODE ABOVE
// To Determine Counts
LOOPER = (LOOPER + 1);
if(LOOPER > (PERIOD)){
LOOPER = 0;
}
delay(2);
}