Alexandre Lemay / Mbed 2 deprecated APP1_s5_A17

Dependencies:   mbed MMA8452

Files at this revision

API Documentation at this revision

Comitter:
evrast
Date:
Tue Sep 05 00:05:38 2017 +0000
Parent:
2:3576839565ae
Parent:
4:ab14f0e33f2b
Child:
6:909e7877d915
Child:
7:b1b4db3eedb4
Commit message:
Merged;

Changed in this revision

Accelerometre.cpp Show annotated file Show diff for this revision Revisions of this file
Accelerometre.h Show annotated file Show diff for this revision Revisions of this file
MainEvr.cpp Show annotated file Show diff for this revision Revisions of this file
maint.cpp Show annotated file Show diff for this revision Revisions of this file
--- 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
+    }
+
--- a/Accelerometre.h	Mon Sep 04 22:57:54 2017 +0000
+++ b/Accelerometre.h	Tue Sep 05 00:05:38 2017 +0000
@@ -1,9 +1,22 @@
 #include "mbed.h"
-/*
+#include "MMA8452.h"
+
 class Accelerometre{
     
-    int readSingleByte(int regist);
-    
+    double const PI = 3.14159265359;
+    int const WRITE_DATA = 0x38;
+    int const READ_DATA = 0x39;
+    MMA8452 acc;
+    I2C i2c;
+
+    Serial pc;
+    public:
+        void writeByte(int Regist,int data);
+        void readxyzAngle(double *angle);
+        int readMultiByte(int regist);
+        Accelerometre();
+        
+    private:
+        double AngleCalculation(double ZValue);
     
-    }
-    */
\ No newline at end of file
+    };
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MMA8452.lib	Tue Sep 05 00:05:38 2017 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/ashleymills/code/MMA8452/#a92a632a0cc7
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MainEvr.cpp	Tue Sep 05 00:05:38 2017 +0000
@@ -0,0 +1,19 @@
+#include "Accelerometre.h"
+
+
+Serial pc(USBTX, USBRX);
+int main() {
+    
+    
+    
+    Accelerometre acc;
+    acc.writeByte(0x2A,0x01);
+    
+    double angle = 0;
+    
+    
+    
+    acc.readxyzAngle(&angle);
+    pc.printf("angle is : %lf\r\n",angle);
+    
+}
\ No newline at end of file
--- a/maint.cpp	Mon Sep 04 22:57:54 2017 +0000
+++ b/maint.cpp	Tue Sep 05 00:05:38 2017 +0000
@@ -1,21 +1,21 @@
-#include "mbed.h"
-#include "Afficheur.h"
-
-#define USESPI
-
-
-Serial pc(USBTX, USBRX); // tx, rx
-
-Afficheur afficheur;
-
-int main() {
-     while(1)
-     {
-        if(pc.readable())
-        {
-            afficheur.write(pc.getc());
-        }
-        
-    }
-    
-}
+//#include "mbed.h"
+//#include "Afficheur.h"
+//
+//#define USESPI
+//
+//
+//Serial pc(USBTX, USBRX); // tx, rx
+//
+//Afficheur afficheur;
+//
+//int main() {
+//     while(1)
+//     {
+//        if(pc.readable())
+//        {
+//            afficheur.write(pc.getc());
+//        }
+//        
+//    }
+//    
+//}