Final

Dependencies:   TextLCD mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Tap.cpp Source File

Tap.cpp

00001 // CS needs to be connected to High in order to do I2C
00002 
00003 #include "Tap.h"
00004 extern I2C acc;
00005 DigitalIn int2(p17);
00006 
00007 char acc_config[2];
00008 const int addr=(0x53<<1);
00009 char data1[1];
00010 char ack;
00011 Timer b;
00012 
00013 
00014 void Tap_init() 
00015     {
00016     wait(0.1);  
00017     acc_config[0]=0x31; acc_config[1]=0x0B;         //data format
00018     ack = acc.write(addr,acc_config, 2);
00019     wait(0.1);
00020       
00021     acc_config[0]=0x2D; acc_config[1]=0x08;         //power control->measure mode
00022     acc.write(addr,acc_config, 2);   
00023     wait(0.1);
00024     
00025     acc_config[0]=0x1D; acc_config[1]=0x50;         //Tap Threshold ->5g 
00026     acc.write(addr,acc_config, 2); 
00027     wait(0.1);
00028     
00029     acc_config[0]=0x21; acc_config[1]=0x10;         //Tap duration -> 0.01
00030     acc.write(addr,acc_config, 2);    
00031     wait(0.1);
00032     
00033     acc_config[0]=0x2A; acc_config[1]=0x07;         //Axis -> x&y&z
00034     acc.write(addr,acc_config, 2);
00035     wait(0.1);
00036     
00037     acc_config[0]=0x2E; acc_config[1]=0x40;         //enable interupt -> single and double tap
00038     acc.write(addr,acc_config, 2);
00039     wait(0.1);
00040     
00041     acc_config[0]=0x2F; acc_config[1]=0x40;         //map interupt ->int2
00042     acc.write(addr,acc_config, 2);
00043     wait(0.1);
00044     }
00045     
00046 void Tap()
00047 {      
00048                     acc_config[0]=0x30;
00049                     acc.write(addr,acc_config,1);            
00050                     acc.read(addr,data1,1);  // Get interupt information                 
00051 }
00052