Write 10 lines of Accelerometer data from FRDM-KL25Z to SD Card and read it back.
Dependencies: MMA8451Q SDFileSystem mbed
Fork of SDCardTest by
Revision 7:dbf3c52ac1b5, committed 2014-12-31
- Comitter:
- ogarai
- Date:
- Wed Dec 31 06:38:35 2014 +0000
- Parent:
- 6:f8e5916f19b8
- Child:
- 8:8d866ae976a3
- Commit message:
- Write 10 lines of sensor data to SD card and read the contents back.
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Tue Dec 30 23:59:23 2014 +0000
+++ b/main.cpp Wed Dec 31 06:38:35 2014 +0000
@@ -5,8 +5,6 @@
SDFileSystem sd(PTD2, PTD3, PTD1, PTD0, "sd");
MMA8451Q acc(PTE25,PTE24);
-
-
int main() {
int16_t data[3];
@@ -14,17 +12,30 @@
if(fp == NULL) {
error("Could not open file for write\n");
}
- while(1)
+
+ for(int i=0;i<10;i++)
{
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]);
- /* if()
- {
- break;
- }*/
+ 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");
}
- fclose(fp);
- printf("Goodbye World!\n");
+ int ch;
+
+ while((ch = fgetc(fp)) != EOF)
+ {
+ printf("%c", ch);
+ }
+ printf("DONE Reading!\n");
+ fclose(fp);
}
\ No newline at end of file
