Use serial port, not SD for datalogging.
Dependencies: MMA8451Q_tb SDFileSystem mbed
Fork of StepLogger by
Revision 1:03f0a25c5a86, committed 2014-05-22
- Comitter:
- donoman
- Date:
- Thu May 22 18:58:25 2014 +0000
- Parent:
- 0:75c161b9fc38
- Commit message:
- Step logging working, but double counting;
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 75c161b9fc38 -r 03f0a25c5a86 main.cpp --- a/main.cpp Wed Apr 30 00:44:56 2014 +0000 +++ b/main.cpp Thu May 22 18:58:25 2014 +0000 @@ -1,6 +1,7 @@ #include "mbed.h" #include "MMA8451Q_tb.h" #include "SDFileSystem.h" +#include "math.h" #define MMA8451_I2C_ADDRESS (0x1d<<1) @@ -13,26 +14,51 @@ int main(void) { //Initialize - int now; //used for timestamping + int now; //used for timestamping + int counter = 0; //used for step counting + int step_flag = 0; //used to sense transition into step + float threshold = 1.43; //tunable in g's [m/s^2] + float mag = 0; + float x = 0; + float y = 0; + float z = 0; timer.start(); MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS); printf("MMA8451 ID: %d\n", acc.getWhoAmI()); //Open File - mkdir("/sd/mydir", 0777); - FILE *fp = fopen("/sd/mydir/sdtest.txt", "a"); - if(fp == NULL) { - error("Could not open file for write\n"); - } + //mkdir("/sd/mydir", 0777); + //FILE *fp = fopen("/sd/mydir/sdtest.txt", "a"); + //if(fp == NULL) { + // error("Could not open file for write\n"); + //} - for(int i=0; i<2000; i++) { + while(1){ + //for(int i=0; i<2000; i++) { pinout = !pinout; now = timer.read_ms(); acc.fastRead(&acc_all[0]); - + x = acc_all[0]; + y = acc_all[1]; + z = acc_all[2]; + + mag = sqrt(x*x + y*y + z*z); //Print to file - fprintf(fp, "%d, %f,%f,%f\n",now, acc_all[0],acc_all[1],acc_all[2]); + // fprintf(fp, "%d, %f,%f,%f\n",now, acc_all[0],acc_all[1],acc_all[2]); + + //} + //fclose(fp); + // pc.printf("mag: %f\n", mag); + if (mag > threshold){ + if (step_flag == 0){ + counter++; + pc.printf("step_count:%d mag: %f\n", counter, mag); + } + step_flag = 1; + } + else { + step_flag = 0; + } } - fclose(fp); }