PARTYYYY

Dependencies:   mbed MMA8452

Revision:
5:70db90b673b9
Parent:
2:3576839565ae
Parent:
4:ab14f0e33f2b
Child:
6:909e7877d915
--- a/Accelerometre.cpp	Mon Sep 04 22:57:54 2017 +0000
+++ b/Accelerometre.cpp	Tue Sep 05 00:05:38 2017 +0000
@@ -1,20 +1,55 @@
 #include "Accelerometre.h"
 
-/*
-
 
-int Accelerometre::readSingleByte(int regis){
-    char cmd[8];
-    int c;
+Accelerometre::Accelerometre():i2c(p9,p10),pc(USBTX, USBRX),acc(p9, p10, 40000){
+    
+   acc.setBitDepth(MMA8452::BIT_DEPTH_12);
+   acc.setDynamicRange(MMA8452::DYNAMIC_RANGE_4G);
+   acc.setDataRate(MMA8452::RATE_100);
+   
+    }
+    
+void Accelerometre::readxyzAngle(double *Angle){
+    double x=0, y=0, z=0;
+    acc.readXYZGravity(&x,&y,&z);
+    *Angle = AngleCalculation(z);
+    
+}
+    
+double Accelerometre::AngleCalculation(double  ZValue){
+    if(ZValue>1){
+        ZValue = 1;
+    }
+    double  angle =std::acos(ZValue);
+    return (angle*180* PI);
+    
+    
+}
+    
+    
+//int Accelerometre::readSingleByte(int regis){
+//    int c;
+//    pc.printf("Reading single byte\n");  
+//    i2c.start();
+//    int a=i2c.write(WRITE_DATA);  // A write to device
+//    i2c.write(regis); // Register to read from (acceleration in X)
+//    i2c.start();        // Need to send start condition here
+//    i2c.write(READ_DATA); // tell devide you want to read
+//    c=i2c.read(0);      
+//    i2c.stop();
+//    pc.printf("value is %d\n", c);
+//    pc.printf("end\n");
+//    return c;
+//    }
+    
+
+void Accelerometre::writeByte(int regis,int data){
     pc.printf("Reading single byte\n");  
     i2c.start();
-    int a=i2c.write(0x38);  // A write to device
+    i2c.write(WRITE_DATA);  // A write to device
     i2c.write(regis); // Register to read from (acceleration in X)
-    i2c.start();        // Need to send start condition here
-    i2c.write(0x39); // tell devide you want to read
-    c=i2c.read(0);      
+    i2c.write(data);
     i2c.stop();
-    pc.printf("value is %d\n", c);
     pc.printf("end\n");
-    return c;
-    }*/
\ No newline at end of file
+    }
+