program for squat device without working usb/bluetooth
Dependencies: 4DGL-uLCD-SE MMA8452 SDFileSystem mbed
main.cpp
- Committer:
- jstai3
- Date:
- 2016-11-18
- Revision:
- 1:de35e7ee2ce0
- Parent:
- 0:d7aa6945b0fd
File content as of revision 1:de35e7ee2ce0:
// Include header files for platform #include "mbed.h" // Include header files for pacman project #include "MMA8452.h" #include "uLCD_4DGL.h" #include "SDFileSystem.h" #include "math.h" //#include "USBHost.h" uLCD_4DGL uLCD(p9,p10,p11); // LCD (serial tx, serial rx, reset pin;) Serial pc(USBTX, USBRX); // used by Accelerometer //Serial bluetooth(p30, p31); MMA8452 Acc(p28, p27, 100000); // Accelerometer SDFileSystem sd(p5, p6, p7, p8, "sd"); // SD card and filesystem (mosi, miso, sck, cs) double x,y,z; double math,angle; int t=0; double baz [500] = { }; #define PI 3.14159265 int main() { // Acc.init(); while(1) { Acc.readXYZGravity(&x, &y, &z); //uLCD.cls(); //uLCD.locate(4,5); //uLCD.printf("Tilt x: %2.2f degree \n", x); // Print the tilt orientation of the X axis //uLCD.printf("Tilt y: %2.2f degree \n", y); // Print the tilt orientation of the Y axis //uLCD.printf("Tilt z: %2.2f degree \n", z); // Print the tilt orientation of the Z axis angle = atan2(y,x); angle = angle * 180/PI; baz [t] = angle; t = t+1; if (t == 100) { break; } //uLCD.printf("Angle: %2.2f \n",angle); //uLCD.printf("t = %2.2d \n",t); //for squat, angle should be between 120 degrees and 140 degrees //for atan2(z,x), angle change is about 45 degrees //bluetooth.printf("test\n"); wait(.2); // short delay until next reading } mkdir("/sd/mydir", 0777); FILE *fp = fopen("/sd/mydir/sdtest.txt", "w"); if(fp == NULL) { error("Could not open file for write\n"); } for(int i = 0;i<500;i++){ fprintf(fp, "%2.2f \n", baz[i]); } fclose(fp); while(1) { uLCD.cls(); uLCD.locate(3,3); uLCD.printf("This works\n"); wait(1); } } //@endcode