#include "mbed.h" LocalFileSystem local("local"); // Create the local filesystem under the name "local" I2C tempsensor(p9,p10);//sda, sc1 Serial pc(USBTX, USBRX); //tx,rx const int addr = 0x90; char config_t[3]; char temp_read[2]; float temp; int main(){ config_t[0] = 0x01; // set pointer reg to 'config register' config_t[1] = 0x60; // config data byte1 config_t[2] = 0xA0; // config data byte2 tempsensor.write(addr,config_t,3); config_t[0] = 0x00; // set pointer reg to 'data register' tempsensor.write(addr,config_t,1); //send to pointer 'read temp' while(1) { wait(1); tempsensor.read(addr,temp_read,2); //read the two-byte temp data temp = 0.0625 *(((temp_read[0] << 8) +temp_read[1]) >> 4); //convert data pc.printf("Temp = %.2f degC \n\r",temp); // Write to local file FILE *fp = fopen("/local/test.txt", "w"); // Open "test.txt" on the local file system for appending for (int i=0; i<120*160; i++) { fprintf(fp, " %.2f",temp); } } }