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@6:f8e5916f19b8, 2014-12-30 (annotated)
- Committer:
- kaushik_ray_1
- Date:
- Tue Dec 30 23:59:23 2014 +0000
- Revision:
- 6:f8e5916f19b8
- Parent:
- 4:823307a8e5dc
- Child:
- 7:dbf3c52ac1b5
Added the Acceleroneter data logging
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
simon | 0:666a082cf50f | 1 | #include "mbed.h" |
simon | 0:666a082cf50f | 2 | #include "SDFileSystem.h" |
kaushik_ray_1 | 6:f8e5916f19b8 | 3 | #include "MMA8451Q.h" |
simon | 0:666a082cf50f | 4 | |
ogarai | 4:823307a8e5dc | 5 | SDFileSystem sd(PTD2, PTD3, PTD1, PTD0, "sd"); |
kaushik_ray_1 | 6:f8e5916f19b8 | 6 | MMA8451Q acc(PTE25,PTE24); |
kaushik_ray_1 | 6:f8e5916f19b8 | 7 | |
kaushik_ray_1 | 6:f8e5916f19b8 | 8 | |
simon | 0:666a082cf50f | 9 | |
simon | 0:666a082cf50f | 10 | int main() { |
kaushik_ray_1 | 6:f8e5916f19b8 | 11 | int16_t data[3]; |
kaushik_ray_1 | 6:f8e5916f19b8 | 12 | |
simon | 0:666a082cf50f | 13 | FILE *fp = fopen("/sd/sdtest.txt", "w"); |
simon | 0:666a082cf50f | 14 | if(fp == NULL) { |
simon | 0:666a082cf50f | 15 | error("Could not open file for write\n"); |
simon | 0:666a082cf50f | 16 | } |
kaushik_ray_1 | 6:f8e5916f19b8 | 17 | while(1) |
kaushik_ray_1 | 6:f8e5916f19b8 | 18 | { |
kaushik_ray_1 | 6:f8e5916f19b8 | 19 | acc.getAccAllAxis(data); |
kaushik_ray_1 | 6:f8e5916f19b8 | 20 | fprintf(fp, "%d",data[0]); |
kaushik_ray_1 | 6:f8e5916f19b8 | 21 | fprintf(fp, ", %d",data[1]); |
kaushik_ray_1 | 6:f8e5916f19b8 | 22 | fprintf(fp, ", %d\n",data[2]); |
kaushik_ray_1 | 6:f8e5916f19b8 | 23 | /* if() |
kaushik_ray_1 | 6:f8e5916f19b8 | 24 | { |
kaushik_ray_1 | 6:f8e5916f19b8 | 25 | break; |
kaushik_ray_1 | 6:f8e5916f19b8 | 26 | }*/ |
kaushik_ray_1 | 6:f8e5916f19b8 | 27 | } |
simon | 0:666a082cf50f | 28 | fclose(fp); |
simon | 0:666a082cf50f | 29 | printf("Goodbye World!\n"); |
kaushik_ray_1 | 6:f8e5916f19b8 | 30 | } |