Accelerations in 3D with Analog Devices ADXL362. The PmodACL2 was used but should work with almost any sensor module with the ADXL362. The ADXL362 connects with SPI. The library ADXL362 published by Analog Devises includes the necessary methods for setting up the sensor and reading the acceleration results.

Dependencies:   ADXL362

Files at this revision

API Documentation at this revision

Comitter:
fanbsun
Date:
Thu Feb 22 20:58:06 2018 +0000
Parent:
0:1ca806626aba
Commit message:
vd

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Thu Feb 22 15:49:12 2018 +0000
+++ b/main.cpp	Thu Feb 22 20:58:06 2018 +0000
@@ -1,5 +1,7 @@
 #include "mbed.h"
 #include "ADXL362.h"
+#include <stdlib.h>
+ 
  
 // Interface pulled from ADXL362.cpp
 // ADXL362::ADXL362(PinName CS, PinName MOSI, PinName MISO, PinName SCK) :
@@ -15,6 +17,15 @@
     adxl362.set_mode(ADXL362::MEASUREMENT);
     
     adxl362_reg_print(0, 3);
+    
+    adx1362_knock_detect();
+    
+    
+    
+    
+    
+    
+    
     return(0);
 }
 
@@ -36,3 +47,41 @@
         return(-1);  
     }    
 }
+
+void adx1362_knock_detect()
+{
+    int8_t x1,y1,z1,x2,y2,z2,x,y,z; 
+    while(1)
+    {
+        
+        while(1) 
+        {
+        x1=adxl362.scanx_u8();
+        y1=adxl362.scany_u8();
+        z1=adxl362.scanz_u8();
+        wait_ms(100);
+        x2=adxl362.scanx_u8();
+        y2=adxl362.scany_u8();
+        z2=adxl362.scanz_u8();
+        
+        x=abs(x1 - x2);
+        y=abs(y1 - y2);
+        z=abs(z1 - z2);
+        
+        if (x>10 || y>10 || z>10)
+        break;
+
+        printf("x = %d y = %d z = %d\r\n",x,y,z);
+        wait_ms(100);
+        }
+        
+        myled = 1;
+        wait(2);
+        
+     }
+        
+        
+        
+        
+        
+        
\ No newline at end of file