Mission Accomplished

Dependencies:   TextLCD mbed

Committer:
pstephens18
Date:
Wed Jan 20 01:01:04 2016 +0000
Revision:
0:96cf16c88314
Final Mission Accomplished
;

Who changed what in which revision?

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