Threads

Dependencies:   mbed C12832 LM75B

main.cpp

Committer:
ciaranom
Date:
2020-11-10
Revision:
6:e883d7b9c790
Parent:
5:608f2bf4d3f7
Child:
7:d20cc6a9060c

File content as of revision 6:e883d7b9c790:

#include "mbed.h"
#include "LM75B.h"
#include "C12832.h"

C12832 lcd(p5, p7, p6, p8, p11);

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()) 
    {
        printf("Device detected!\n");
        while (i < 5) 
        {
            lcd.cls();
            lcd.locate(0,3);
            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];

   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