program for squat device without working usb/bluetooth

Dependencies:   4DGL-uLCD-SE MMA8452 SDFileSystem mbed

Committer:
jstai3
Date:
Fri Nov 18 20:59:37 2016 +0000
Revision:
1:de35e7ee2ce0
Parent:
0:d7aa6945b0fd
records acc data 5x per second;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jstai3 0:d7aa6945b0fd 1 // Include header files for platform
jstai3 0:d7aa6945b0fd 2 #include "mbed.h"
jstai3 0:d7aa6945b0fd 3
jstai3 0:d7aa6945b0fd 4 // Include header files for pacman project
jstai3 0:d7aa6945b0fd 5 #include "MMA8452.h"
jstai3 0:d7aa6945b0fd 6 #include "uLCD_4DGL.h"
jstai3 0:d7aa6945b0fd 7 #include "SDFileSystem.h"
jstai3 0:d7aa6945b0fd 8 #include "math.h"
jstai3 1:de35e7ee2ce0 9 //#include "USBHost.h"
jstai3 0:d7aa6945b0fd 10
jstai3 0:d7aa6945b0fd 11
jstai3 0:d7aa6945b0fd 12 uLCD_4DGL uLCD(p9,p10,p11); // LCD (serial tx, serial rx, reset pin;)
jstai3 1:de35e7ee2ce0 13 Serial pc(USBTX, USBRX); // used by Accelerometer
jstai3 1:de35e7ee2ce0 14 //Serial bluetooth(p30, p31);
jstai3 0:d7aa6945b0fd 15 MMA8452 Acc(p28, p27, 100000); // Accelerometer
jstai3 0:d7aa6945b0fd 16 SDFileSystem sd(p5, p6, p7, p8, "sd"); // SD card and filesystem (mosi, miso, sck, cs)
jstai3 0:d7aa6945b0fd 17 double x,y,z;
jstai3 1:de35e7ee2ce0 18 double math,angle;
jstai3 1:de35e7ee2ce0 19 int t=0;
jstai3 1:de35e7ee2ce0 20 double baz [500] = { };
jstai3 0:d7aa6945b0fd 21 #define PI 3.14159265
jstai3 0:d7aa6945b0fd 22
jstai3 0:d7aa6945b0fd 23 int main()
jstai3 0:d7aa6945b0fd 24 {
jstai3 0:d7aa6945b0fd 25 // Acc.init();
jstai3 0:d7aa6945b0fd 26 while(1)
jstai3 0:d7aa6945b0fd 27 {
jstai3 0:d7aa6945b0fd 28 Acc.readXYZGravity(&x, &y, &z);
jstai3 0:d7aa6945b0fd 29
jstai3 1:de35e7ee2ce0 30 //uLCD.cls();
jstai3 1:de35e7ee2ce0 31 //uLCD.locate(4,5);
jstai3 1:de35e7ee2ce0 32 //uLCD.printf("Tilt x: %2.2f degree \n", x); // Print the tilt orientation of the X axis
jstai3 1:de35e7ee2ce0 33 //uLCD.printf("Tilt y: %2.2f degree \n", y); // Print the tilt orientation of the Y axis
jstai3 1:de35e7ee2ce0 34 //uLCD.printf("Tilt z: %2.2f degree \n", z); // Print the tilt orientation of the Z axis
jstai3 0:d7aa6945b0fd 35
jstai3 0:d7aa6945b0fd 36 angle = atan2(y,x);
jstai3 0:d7aa6945b0fd 37 angle = angle * 180/PI;
jstai3 1:de35e7ee2ce0 38 baz [t] = angle;
jstai3 1:de35e7ee2ce0 39 t = t+1;
jstai3 1:de35e7ee2ce0 40 if (t == 100) {
jstai3 1:de35e7ee2ce0 41 break;
jstai3 1:de35e7ee2ce0 42 }
jstai3 1:de35e7ee2ce0 43 //uLCD.printf("Angle: %2.2f \n",angle);
jstai3 1:de35e7ee2ce0 44 //uLCD.printf("t = %2.2d \n",t);
jstai3 0:d7aa6945b0fd 45 //for squat, angle should be between 120 degrees and 140 degrees
jstai3 0:d7aa6945b0fd 46 //for atan2(z,x), angle change is about 45 degrees
jstai3 0:d7aa6945b0fd 47
jstai3 1:de35e7ee2ce0 48 //bluetooth.printf("test\n");
jstai3 1:de35e7ee2ce0 49 wait(.2); // short delay until next reading
jstai3 1:de35e7ee2ce0 50 }
jstai3 1:de35e7ee2ce0 51 mkdir("/sd/mydir", 0777);
jstai3 1:de35e7ee2ce0 52
jstai3 1:de35e7ee2ce0 53 FILE *fp = fopen("/sd/mydir/sdtest.txt", "w");
jstai3 1:de35e7ee2ce0 54 if(fp == NULL) {
jstai3 1:de35e7ee2ce0 55 error("Could not open file for write\n");
jstai3 1:de35e7ee2ce0 56 }
jstai3 1:de35e7ee2ce0 57 for(int i = 0;i<500;i++){
jstai3 1:de35e7ee2ce0 58 fprintf(fp, "%2.2f \n", baz[i]);
jstai3 1:de35e7ee2ce0 59 }
jstai3 1:de35e7ee2ce0 60 fclose(fp);
jstai3 1:de35e7ee2ce0 61 while(1)
jstai3 1:de35e7ee2ce0 62 {
jstai3 1:de35e7ee2ce0 63 uLCD.cls();
jstai3 1:de35e7ee2ce0 64 uLCD.locate(3,3);
jstai3 1:de35e7ee2ce0 65 uLCD.printf("This works\n");
jstai3 1:de35e7ee2ce0 66 wait(1);
jstai3 0:d7aa6945b0fd 67 }
jstai3 0:d7aa6945b0fd 68
jstai3 0:d7aa6945b0fd 69 }
jstai3 0:d7aa6945b0fd 70
jstai3 0:d7aa6945b0fd 71 //@endcode
jstai3 0:d7aa6945b0fd 72
jstai3 0:d7aa6945b0fd 73