Write 10 lines of Accelerometer data from FRDM-KL25Z to SD Card and read it back.
Dependencies: MMA8451Q SDFileSystem mbed
Fork of SDCardTest by
main.cpp
- Committer:
- ogarai
- Date:
- 2014-12-31
- Revision:
- 8:8d866ae976a3
- Parent:
- 7:dbf3c52ac1b5
File content as of revision 8:8d866ae976a3:
#include "mbed.h"
#include "SDFileSystem.h"
#include "MMA8451Q.h"
SDFileSystem sd(PTD2, PTD3, PTD1, PTD0, "sd");
MMA8451Q acc(PTE25,PTE24);
int main() {
int16_t data[3];
FILE *fp = fopen("/sd/sdtest.txt", "w");
if(fp == NULL) {
error("Could not open file for write\n");
}
// Enable the below line and disable the next line for testing
// for(int i=0;i<10;i++)
while(1)
{
acc.getAccAllAxis(data);
fprintf(fp, "%d",data[0]);
printf("%d",data[0]);
fprintf(fp, ", %d",data[1]);
printf(", %d",data[1]);
fprintf(fp, ", %d\n",data[2]);
printf(", %d\n",data[2]);
}
fclose(fp);
printf("Done Writing! Now Reading... \n");
fp = fopen("/sd/sdtest.txt", "r");
if(fp == NULL) {
error("Could not open file for read\n");
}
int ch;
while((ch = fgetc(fp)) != EOF)
{
printf("%c", ch);
}
printf("DONE Reading!\n");
fclose(fp);
}
