Mission Accomplished

Dependencies:   TextLCD mbed

Revision:
0:96cf16c88314
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Tap.cpp	Wed Jan 20 01:01:04 2016 +0000
@@ -0,0 +1,52 @@
+// CS needs to be connected to High in order to do I2C
+
+#include "Tap.h"
+extern I2C acc;
+DigitalIn int2(p17);
+
+char acc_config[2];
+const int addr=(0x53<<1);
+char data1[1];
+char ack;
+Timer b;
+
+
+void Tap_init() 
+    {
+    wait(0.1);  
+    acc_config[0]=0x31; acc_config[1]=0x0B;         //data format
+    ack = acc.write(addr,acc_config, 2);
+    wait(0.1);
+      
+    acc_config[0]=0x2D; acc_config[1]=0x08;         //power control->measure mode
+    acc.write(addr,acc_config, 2);   
+    wait(0.1);
+    
+    acc_config[0]=0x1D; acc_config[1]=0x50;         //Tap Threshold ->5g 
+    acc.write(addr,acc_config, 2); 
+    wait(0.1);
+    
+    acc_config[0]=0x21; acc_config[1]=0x10;         //Tap duration -> 0.01
+    acc.write(addr,acc_config, 2);    
+    wait(0.1);
+    
+    acc_config[0]=0x2A; acc_config[1]=0x07;         //Axis -> x&y&z
+    acc.write(addr,acc_config, 2);
+    wait(0.1);
+    
+    acc_config[0]=0x2E; acc_config[1]=0x40;         //enable interupt -> single and double tap
+    acc.write(addr,acc_config, 2);
+    wait(0.1);
+    
+    acc_config[0]=0x2F; acc_config[1]=0x40;         //map interupt ->int2
+    acc.write(addr,acc_config, 2);
+    wait(0.1);
+    }
+    
+void Tap()
+{      
+                    acc_config[0]=0x30;
+                    acc.write(addr,acc_config,1);            
+                    acc.read(addr,data1,1);  // Get interupt information                 
+}
+