Ben Michael
/
miniProject4
Servo that turns towards heat source with temperature reading display.
tempSnsr.cpp
- Committer:
- bmichael21
- Date:
- 2019-01-14
- Revision:
- 17:fc23cf904932
- Parent:
- 15:1eed07b5a5ba
File content as of revision 17:fc23cf904932:
#include "tempSnsr.h" AnalogIn tempSnsr1(p16); AnalogIn tempSnsr2(p17); float curDiff, temp1, temp2, prevDiff; float highTemp(){ //this function used for display information. Temperatures not updated here to avoid changing values in the middle //of the while true loop in main. if(curDiff > 0) return temp1; //temp1 and temp2 are already converted to farenheit measurements else return temp2; } void avgTemps(){ //this function is only used in this file to get readings from both sensors while minimizing variance in readings temp1 = 0; temp2 = 0; for(int i = 0; i < 10; i++){ temp1 += tempSnsr1; temp2 += tempSnsr2; } temp1 = (temp1 * 10 * 3.3 - 50) * 1.8 + 32; //conversion to the actual temperature in farenheit allows for reusability of function temp2 = (temp2 * 10 * 3.3 - 50) * 1.8 + 32; } void updateTempDifference(){ //this is the function called by main to update the previous and current temperature readings avgTemps(); prevDiff = curDiff; curDiff = temp1 - temp2; }