Final

Dependencies:   TextLCD mbed

Committer:
pstephens18
Date:
Wed Jan 20 02:15:26 2016 +0000
Revision:
0:5fd3f73db34f
final

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pstephens18 0:5fd3f73db34f 1 // CS needs to be connected to High in order to do I2C
pstephens18 0:5fd3f73db34f 2
pstephens18 0:5fd3f73db34f 3 #include "Tap.h"
pstephens18 0:5fd3f73db34f 4 extern I2C acc;
pstephens18 0:5fd3f73db34f 5 DigitalIn int2(p17);
pstephens18 0:5fd3f73db34f 6
pstephens18 0:5fd3f73db34f 7 char acc_config[2];
pstephens18 0:5fd3f73db34f 8 const int addr=(0x53<<1);
pstephens18 0:5fd3f73db34f 9 char data1[1];
pstephens18 0:5fd3f73db34f 10 char ack;
pstephens18 0:5fd3f73db34f 11 Timer b;
pstephens18 0:5fd3f73db34f 12
pstephens18 0:5fd3f73db34f 13
pstephens18 0:5fd3f73db34f 14 void Tap_init()
pstephens18 0:5fd3f73db34f 15 {
pstephens18 0:5fd3f73db34f 16 wait(0.1);
pstephens18 0:5fd3f73db34f 17 acc_config[0]=0x31; acc_config[1]=0x0B; //data format
pstephens18 0:5fd3f73db34f 18 ack = acc.write(addr,acc_config, 2);
pstephens18 0:5fd3f73db34f 19 wait(0.1);
pstephens18 0:5fd3f73db34f 20
pstephens18 0:5fd3f73db34f 21 acc_config[0]=0x2D; acc_config[1]=0x08; //power control->measure mode
pstephens18 0:5fd3f73db34f 22 acc.write(addr,acc_config, 2);
pstephens18 0:5fd3f73db34f 23 wait(0.1);
pstephens18 0:5fd3f73db34f 24
pstephens18 0:5fd3f73db34f 25 acc_config[0]=0x1D; acc_config[1]=0x50; //Tap Threshold ->5g
pstephens18 0:5fd3f73db34f 26 acc.write(addr,acc_config, 2);
pstephens18 0:5fd3f73db34f 27 wait(0.1);
pstephens18 0:5fd3f73db34f 28
pstephens18 0:5fd3f73db34f 29 acc_config[0]=0x21; acc_config[1]=0x10; //Tap duration -> 0.01
pstephens18 0:5fd3f73db34f 30 acc.write(addr,acc_config, 2);
pstephens18 0:5fd3f73db34f 31 wait(0.1);
pstephens18 0:5fd3f73db34f 32
pstephens18 0:5fd3f73db34f 33 acc_config[0]=0x2A; acc_config[1]=0x07; //Axis -> x&y&z
pstephens18 0:5fd3f73db34f 34 acc.write(addr,acc_config, 2);
pstephens18 0:5fd3f73db34f 35 wait(0.1);
pstephens18 0:5fd3f73db34f 36
pstephens18 0:5fd3f73db34f 37 acc_config[0]=0x2E; acc_config[1]=0x40; //enable interupt -> single and double tap
pstephens18 0:5fd3f73db34f 38 acc.write(addr,acc_config, 2);
pstephens18 0:5fd3f73db34f 39 wait(0.1);
pstephens18 0:5fd3f73db34f 40
pstephens18 0:5fd3f73db34f 41 acc_config[0]=0x2F; acc_config[1]=0x40; //map interupt ->int2
pstephens18 0:5fd3f73db34f 42 acc.write(addr,acc_config, 2);
pstephens18 0:5fd3f73db34f 43 wait(0.1);
pstephens18 0:5fd3f73db34f 44 }
pstephens18 0:5fd3f73db34f 45
pstephens18 0:5fd3f73db34f 46 void Tap()
pstephens18 0:5fd3f73db34f 47 {
pstephens18 0:5fd3f73db34f 48 acc_config[0]=0x30;
pstephens18 0:5fd3f73db34f 49 acc.write(addr,acc_config,1);
pstephens18 0:5fd3f73db34f 50 acc.read(addr,data1,1); // Get interupt information
pstephens18 0:5fd3f73db34f 51 }
pstephens18 0:5fd3f73db34f 52