Ben Michael
/
miniProject4
Servo that turns towards heat source with temperature reading display.
tempSnsr.cpp@9:0f2b584e419c, 2019-01-14 (annotated)
- Committer:
- bmichael21
- Date:
- Mon Jan 14 04:04:24 2019 +0000
- Revision:
- 9:0f2b584e419c
- Parent:
- 8:fb50cf601521
- Child:
- 11:362594298828
made the servo movement direction factor in the previous temperature readings
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bmichael21 | 2:24a919513911 | 1 | #include "tempSnsr.h" |
bmichael21 | 2:24a919513911 | 2 | |
bmichael21 | 3:6d27738a83dc | 3 | AnalogIn tempSnsr1(p16); |
bmichael21 | 3:6d27738a83dc | 4 | AnalogIn tempSnsr2(p17); |
bmichael21 | 3:6d27738a83dc | 5 | |
bmichael21 | 9:0f2b584e419c | 6 | float curdiff, temp1, temp2, prevDiff; |
bmichael21 | 9:0f2b584e419c | 7 | |
bmichael21 | 9:0f2b584e419c | 8 | float highTemp(){ //this function used for display information. Temperatures not updated here to avoid changing values in the middle |
bmichael21 | 9:0f2b584e419c | 9 | //of the while true loop in main. |
bmichael21 | 9:0f2b584e419c | 10 | if(curDiff > 0) |
bmichael21 | 3:6d27738a83dc | 11 | return temp1; //temp1 and temp2 are already converted to farenheit measurements |
bmichael21 | 3:6d27738a83dc | 12 | else |
bmichael21 | 3:6d27738a83dc | 13 | return temp2; |
bmichael21 | 3:6d27738a83dc | 14 | } |
bmichael21 | 3:6d27738a83dc | 15 | |
bmichael21 | 9:0f2b584e419c | 16 | void avgTemps(){ //this function is only used in this file to get readings from both sensors while minimizing variance in readings |
bmichael21 | 9:0f2b584e419c | 17 | temp1 = 0; |
bmichael21 | 9:0f2b584e419c | 18 | temp2 = 0; |
bmichael21 | 3:6d27738a83dc | 19 | for(int i = 0; i < 10; i++){ |
bmichael21 | 3:6d27738a83dc | 20 | temp1 += tempSnsr1; |
bmichael21 | 9:0f2b584e419c | 21 | temp2 += tempSnsr2; |
bmichael21 | 3:6d27738a83dc | 22 | } |
bmichael21 | 9:0f2b584e419c | 23 | temp1 = (temp1 * 10 * 3.3 - 0.5) * 1.8 + 32; //conversion to the actual temperature in farenheit allows for reusability of function |
bmichael21 | 9:0f2b584e419c | 24 | temp2 = (temp2 * 10 * 3.3 - 0.5) * 1.8 + 32; |
bmichael21 | 3:6d27738a83dc | 25 | } |
bmichael21 | 3:6d27738a83dc | 26 | |
bmichael21 | 9:0f2b584e419c | 27 | void updateTempDifference(){ //this is the function called by main to update the previous and current temperature readings |
bmichael21 | 9:0f2b584e419c | 28 | avgTemps(); |
bmichael21 | 9:0f2b584e419c | 29 | prevDiff = curDiff; |
bmichael21 | 9:0f2b584e419c | 30 | curDiff = temp1 - temp2; |
bmichael21 | 3:6d27738a83dc | 31 | } |