A Team / SDCardTest

Dependencies:   MMA8451Q SDFileSystem mbed

Fork of SDCardTest by Orko Garai

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "SDFileSystem.h"
00003 #include "MMA8451Q.h"
00004 
00005 SDFileSystem sd(PTD2, PTD3, PTD1, PTD0, "sd");
00006 MMA8451Q acc(PTE25,PTE24);
00007 
00008 int main() {
00009     int16_t data[3];
00010     
00011     FILE *fp = fopen("/sd/sdtest.txt", "w");
00012     if(fp == NULL) {
00013         error("Could not open file for write\n");
00014     }
00015     // Enable the below line and disable the next line for testing
00016 //    for(int i=0;i<10;i++)
00017     while(1)
00018     {
00019         acc.getAccAllAxis(data);  
00020         fprintf(fp, "%d",data[0]);
00021         printf("%d",data[0]);
00022         fprintf(fp, ", %d",data[1]);
00023         printf(", %d",data[1]);
00024         fprintf(fp, ", %d\n",data[2]);
00025         printf(", %d\n",data[2]);
00026     }
00027     fclose(fp);
00028     printf("Done Writing! Now Reading... \n");
00029     
00030     fp = fopen("/sd/sdtest.txt", "r");
00031     if(fp == NULL) {
00032         error("Could not open file for read\n");
00033     }
00034     int ch;
00035     
00036     while((ch = fgetc(fp)) != EOF)
00037     {
00038         printf("%c", ch);
00039     }
00040     printf("DONE Reading!\n");
00041     fclose(fp);
00042 }