PARTYYYY

Dependencies:   mbed MMA8452

Files at this revision

API Documentation at this revision

Comitter:
evrast
Date:
Tue Sep 05 05:51:17 2017 +0000
Parent:
5:70db90b673b9
Child:
8:5124be43c963
Commit message:
je dormais;

Changed in this revision

Accelerometre.cpp Show annotated file Show diff for this revision Revisions of this file
Afficheur.cpp Show annotated file Show diff for this revision Revisions of this file
Afficheur.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
--- a/Accelerometre.cpp	Tue Sep 05 00:05:38 2017 +0000
+++ b/Accelerometre.cpp	Tue Sep 05 05:51:17 2017 +0000
@@ -1,10 +1,10 @@
 #include "Accelerometre.h"
 
 
-Accelerometre::Accelerometre():i2c(p9,p10),pc(USBTX, USBRX),acc(p9, p10, 40000){
+Accelerometre::Accelerometre():i2c(p28,p27),pc(USBTX, USBRX),acc(p28, p27, 40000){
     
    acc.setBitDepth(MMA8452::BIT_DEPTH_12);
-   acc.setDynamicRange(MMA8452::DYNAMIC_RANGE_4G);
+   acc.setDynamicRange(MMA8452::DYNAMIC_RANGE_2G);
    acc.setDataRate(MMA8452::RATE_100);
    
     }
@@ -20,8 +20,11 @@
     if(ZValue>1){
         ZValue = 1;
     }
+    if(ZValue <-1){
+        ZValue = -1;    
+    }
     double  angle =std::acos(ZValue);
-    return (angle*180* PI);
+    return (angle*180/ PI);
     
     
 }
--- a/Afficheur.cpp	Tue Sep 05 00:05:38 2017 +0000
+++ b/Afficheur.cpp	Tue Sep 05 05:51:17 2017 +0000
@@ -9,11 +9,18 @@
         chipSelect = 0;
     }
     
-    void Afficheur::write(char* characters,int length ) 
+    void Afficheur::write(char* characters,int length,int expo ) 
     {
+        
+Serial pc(USBTX, USBRX);
+        pc.printf("1");
         static char buf[20];
+        pc.printf("2");
         resetDisplay();
-        afficheur.write(characters,length,buf,20);      
+        pc.printf("3");
+        afficheur.write(characters,length,buf,20);
+        pc.printf("4");
+        showDot(expo);    
     }
     void Afficheur::write(char ch)
     {
@@ -25,9 +32,9 @@
         char buf[1];
         afficheur.write("v",1,buf,1);
     }
-    void Afficheur::showDot()
+    void Afficheur::showDot(int expo)
     {
-        char command[2] = {'w',2};
+        char command[2] = {'w',expo};
         char buf[2];
         afficheur.write(command,2,buf, 2);
     }
--- a/Afficheur.h	Tue Sep 05 00:05:38 2017 +0000
+++ b/Afficheur.h	Tue Sep 05 05:51:17 2017 +0000
@@ -7,10 +7,10 @@
 public:
     Afficheur();
     
-    void write(char* characters,int length );
+    void write(char* characters,int length ,int expo);
     void write(char ch);
     void resetDisplay();
-    void showDot();
+    void showDot(int expo);
     void hideDot();
     
     private:
--- a/MainEvr.cpp	Tue Sep 05 00:05:38 2017 +0000
+++ b/MainEvr.cpp	Tue Sep 05 05:51:17 2017 +0000
@@ -1,19 +1,45 @@
 #include "Accelerometre.h"
-
+#include "Afficheur.h"
 
 Serial pc(USBTX, USBRX);
 int main() {
     
-    
+
     
+    Afficheur afficheur;
     Accelerometre acc;
-    acc.writeByte(0x2A,0x01);
     
     double angle = 0;
     
+    while(true){
     
+        acc.readxyzAngle(&angle);
+        pc.printf("angle is : %lf\r\n",angle);
+        
+        
+        
+        char c1[10];
+        char c2[4];
     
-    acc.readxyzAngle(&angle);
-    pc.printf("angle is : %lf\r\n",angle);
-    
+        sprintf(c1 , "%4f" , angle);
+        int virgule;
+        int j =0;
+        for(int i =0;i<4;i++){
+            if(c1[j] == '.'){
+                virgule =  1 <<j-1;
+                i--;
+                j++;
+                continue;
+            }
+            c2[i] =  c1[j];
+            j++;
+            
+        }
+        
+        pc.printf("virg= %d",virgule);
+        afficheur.write(c2,4, virgule);
+        
+        pc.printf("test");
+        wait(0.45);
+    }
 }
\ No newline at end of file