program for squat device without working usb/bluetooth

Dependencies:   4DGL-uLCD-SE MMA8452 SDFileSystem mbed

main.cpp

Committer:
jstai3
Date:
2016-11-13
Revision:
0:d7aa6945b0fd
Child:
1:de35e7ee2ce0

File content as of revision 0:d7aa6945b0fd:

// 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
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;
#define PI 3.14159265



 


 
 int main() 
 {
 //   Acc.init(); 
       while(1)
       {
           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
            
           angle = atan2(y,x);
        angle = angle * 180/PI;
        
        uLCD.printf("Angle: %2.2f \n",angle);
        //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
 
    }
 
}
 
//@endcode