Hayley Cashdollar / Mbed 2 deprecated LocalFileSystem_Read

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 Serial pc(USBTX, USBRX); // tx, rx
00004 DigitalOut myled(LED1);
00005 
00006 float     Right=1.123456;  // gemeten waarde bij 4mA ( 0..1 <> 0..3.3v )
00007 float     Left=1.123;  // gemeten waarde bij 4mA ( 0..1 <> 0..3.3v )
00008 char A[10], B[10];
00009 
00010 LocalFileSystem local("local");               // Create the local filesystem under the name "local"
00011 //float leftOff;
00012 
00013 
00014 
00015 void ReadFile (void)
00016 {
00017     FILE *set = fopen("/local/calib.txt", "r");  // Open "setup.txt" on the local file system for read
00018     fscanf(set,"%s %f",A,&Left); // read offset
00019     fscanf(set,"%s %f",A,&Right); // read offset
00020     fclose(set);
00021 }
00022 
00023 
00024 void WriteFile(void)   // write to USB memory
00025 {
00026     FILE *fp = fopen("/local/calib.txt", "w");  // Open "setup.txt" on the local file system for write
00027     fprintf(fp,"Left %f\r\n",Left); // read offset
00028     fprintf(fp,"Right %f\r\n",Right); // read offset
00029     //fprintf(fp,"gain %f\r\n",lOffset);   // read gain
00030     fclose(fp);
00031 }
00032 
00033 
00034 int main()
00035 {
00036     pc.baud(912600);
00037     WriteFile();
00038     wait(3);
00039     ReadFile();// when you run first time without this line, the setup file is on created
00040     wait(1);
00041     pc.printf("Left Offset is: %f, Right Offset is: %f\r\n", Left, Right);
00042     //pc.printf("%f\n roffset", roff);
00043 }