program for squat device without working usb/bluetooth
Dependencies: 4DGL-uLCD-SE MMA8452 SDFileSystem mbed
Revision 1:de35e7ee2ce0, committed 2016-11-18
- Comitter:
- jstai3
- Date:
- Fri Nov 18 20:59:37 2016 +0000
- Parent:
- 0:d7aa6945b0fd
- Commit message:
- records acc data 5x per second;
Changed in this revision
USBHost.lib | Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/USBHost.lib Sun Nov 13 21:53:12 2016 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://developer.mbed.org/users/sparkfun/code/USBHost/#220cd93c9a5f
--- a/main.cpp Sun Nov 13 21:53:12 2016 +0000 +++ b/main.cpp Fri Nov 18 20:59:37 2016 +0000 @@ -6,22 +6,19 @@ #include "uLCD_4DGL.h" #include "SDFileSystem.h" #include "math.h" -#include "USBHost.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 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 angle,math; +double math,angle; +int t=0; +double baz [500] = { }; #define PI 3.14159265 - - - - - - int main() { @@ -30,28 +27,43 @@ { Acc.readXYZGravity(&x, &y, &z); - - - //Acc.read_x_raw(char x); - //Acc.read_y_raw(char y); - //Acc.read_z_raw(char 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 + //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; - - uLCD.printf("Angle: %2.2f \n",angle); + 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 - - wait(1); // short delay until next reading - + //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); } }