Lab 10/24/18

Dependencies:   mbed

Fork of I2C_MCP9808_V2 by Advanced_Instrumentation_2019

Revision:
1:568629da46dd
Parent:
0:80fb3c4621be
--- a/main.cpp	Tue Oct 23 19:39:34 2018 +0000
+++ b/main.cpp	Tue Oct 30 22:12:34 2018 +0000
@@ -32,13 +32,18 @@
     // Wake up
     data_write[0] = MCP9808_REG_CONF; // Register address
     data_write[1] = 0x00;  // Data MSB, b11-15 not used, b9-10 =>T_HYS=0, b8 => continuous conversions
-    data_write[2] = 0x04;  // Data LSB,  Alert Off, Alert Disabled, Alert T>T_Crit, Alert active low, Alert interrupt
+    data_write[2] = 0x1C;  // Data LSB,  Alert Off, Alert Disabled, Alert T>T_Crit, Alert active low, Alert interrupt
     status = i2c.write(MCP9808_ADDR, data_write, 3, 0); // address,data,length,repeat
     // address is chip addess
     // First byte of data has register address 
     // repeat true for multiple write when the chip autoincrements the address
     // MCP9808 does not do this, so we leave it at 0
-      
+     
+    data_write[0] = MCP9808_REG_CRIT; // Register address
+    data_write[1] = 0x01;  
+    data_write[2] = 0x70;  
+    status = i2c.write(MCP9808_ADDR, data_write, 3, 0); // address,data,length,repeat
+ 
     while(1){
         int i=0;
         // this loops takes 10 data points and then
@@ -50,16 +55,24 @@
             i2c.read(MCP9808_ADDR, data_read, 2, 0);
             status = data_read[0] >> 5;  // Shift flags to b0-b2
             // 1 in flag means: T>T_crit(b2), T>T_Upper(b1), T<T_Lower(b0)
-           // pc.printf("the status is %n",status);
+            pc.printf("the status is %d\n\r",status);
+           
+           
             data_read[0] = data_read[0] & 0x1F;  // clear flag bits for temperature
             
             data[i] = (data_read[0] * 16) + (data_read[1] / 16.0); // combine two bytes
             // Display the flags, if you wish
             // pc.printf("Flags are %i \n\r",status);
             // This displays to the user
-            pc.printf("%i Temperature is %3.1f\n\r",i,data[i]);
+            float temperature_fahr = data[i]*(9.0/5)+32;
+            pc.printf("%i Celsius temperature is %3.1f\n\r",i,data[i]);
+            pc.printf("%i Fahrenheit temperature is %3.1f\n\r",i,temperature_fahr);
             i=i+1;
             wait(1);
+            
+            if (data_read[0] > 24){
+                
+            }
         }
                 
         myLogFile = fopen("/local/log.txt", "a"); // open log.txt as a write only file (any existing file will be overwritten). Replace "w" with "a" to append