Jason Schilling / Mbed 2 deprecated miniProject7

Dependencies:   mbed TextLCD

Revision:
5:8582a28cf944
Parent:
4:19878f73f3e3
--- a/Temperature.cpp	Thu Jan 17 00:12:40 2019 +0000
+++ b/Temperature.cpp	Thu Jan 17 06:04:45 2019 +0000
@@ -1,35 +1,43 @@
 #include "Temperature.h"
 I2C i2cTemp(p9, p10);
+volatile short rawTemp;
     
-float tempFar(float temp) {
+float tempFar(float temp) { // converts temperature to farenheit
     float far;
-    far = (temp*9/5)+32;
+    far = (((0.0625 * rawTemp)*(9/5))+32);
     return far;
 }
 
-float tempRan(float temp) {
+float tempRan(float temp) { // converts temperature to rankine
     float ran;
-    ran = (temp*9/5)+491.67;
+    ran = (((0.0625 * rawTemp)*(9/5))+491.67);
     return ran;
 }
 
-float tempKel(float temp){
+float tempKel(float temp){ // cocnverts temperature to kelvin
     float kel;
-    kel = temp+273;
+    kel = ((0.0625 * rawTemp)+273);
     return kel;
 }
 
-void tempConfig(void) {
-    
+void tempConfig(void) { // configures the correct settings for the temperature sensor when the program starts
+    char buff[3];
+    const int tempAddr = 0x90;
+    buff[0] = 0x01;
+    buff[1] = 0x60;
+    buff[2] = 0xA0;
+    i2cTemp.write(tempAddr, buff, 3);
+    buff[0] = 0x00;
+    i2cTemp.write(tempAddr, buff, 1);    
 }
 
-float readTemp(rawTemp) {
-    short rawTemp;
+float readTemp() { // converts rawTemp (the raw data from the temperature sensor) to degrees celsius
     float temp;
     char buff[2];
     const int tempAddr = 0x90;
-    tempSensor.read(tempAddr, buff, 2);
+    i2cTemp.read(tempAddr, buff, 2);
     rawTemp = (buff[0] <<8) + buff[1];
     rawTemp = rawTemp >> 4;
     temp = 0.0625 * rawTemp;
+    return temp;
 }
\ No newline at end of file