Threads

Dependencies:   mbed C12832 LM75B

Revision:
6:e883d7b9c790
Parent:
5:608f2bf4d3f7
Child:
7:d20cc6a9060c
--- a/main.cpp	Thu Feb 06 14:05:51 2014 +0000
+++ b/main.cpp	Tue Nov 10 12:11:20 2020 +0000
@@ -7,22 +7,62 @@
 LM75B sensor(p28,p27);
 Serial pc(USBTX,USBRX);
 
+
+
 int main ()
 {
-
+    //variables 
+    LocalFileSystem local("local");               // Create the local filesystem under the name "local"
+    FILE *fp = fopen("/local/temp2.csv", "w");  // Open "out.txt" on the local file system for writing
+    int i =0;
+    //float temps [5];
+    //float sensorval;
     //Try to open the LM75B
-    if (sensor.open()) {
+    if (sensor.open()) 
+    {
         printf("Device detected!\n");
-
-        while (1) {
+        while (i < 5) 
+        {
             lcd.cls();
             lcd.locate(0,3);
-            lcd.printf("Temp = %.3f\n", (float)sensor);
-            wait(1.0);
-        }
+            lcd.printf("Temp = %.3f", (float)sensor);
+            wait(0.5);
+            fprintf(fp, "%.3f,", (float)sensor);
+            //cur_temp = (float)sensor;
+            //sensorval = (float)sensor;
+            //printf("\n\r %.3f\n\r",sensorval);
+            //temps[i] = sensorval;
+            //pc.   printf("%.3f ",temps[i]);
+            i = i+1;
+            wait(0.5);
+        }//end while loop
+    } 
+    else
+    {
+        error("Device not detected!\n");
+    }//end if sensor open
+    
+    //for(int j = 0; j<i; j++) //causing infinite loop 
+   
+        
+    //close files        
+    fclose(fp);
+    
+       FILE * pFile;
+   char mystring [5];
 
-    } else {
-        error("Device not detected!\n");
+   pFile = fopen ("/local/temp2.csv" , "r");
+   if (pFile == NULL) perror ("Error opening file");
+   else {
+     if ( fgets (mystring , 5 , pFile) != NULL )
+       pc.printf(mystring);
+     fclose (pFile);
+     //pc.printf("%.3f ",temps[i]);
+   }
+   return 0;
+   
+    //printf("%.3f",temps[i]);
     }
+//end main
 
-}
+