1+ /*
2+ Copyright (c) 2015 Intel Corporation. All rights reserved.
3+
4+ This library is free software; you can redistribute it and/or
5+ modify it under the terms of the GNU Lesser General Public
6+ License as published by the Free Software Foundation; either
7+ version 2.1 of the License, or (at your option) any later version.
8+
9+ This library is distributed in the hope that it will be useful,
10+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+ Lesser General Public License for more details.
13+
14+ You should have received a copy of the GNU Lesser General Public
15+ License along with this library; if not, write to the Free Software
16+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17+
18+ */
19+
20+ /*
21+ This sketch example demonstrates how the BMI160 accelerometer on the
22+ Intel(R) Curie(TM) module can be used to detect tap events
23+ */
24+
25+ #include " CurieIMU.h"
26+
27+ void setup () {
28+ Serial.begin (9600 );
29+
30+ // Initialise the IMU
31+ CurieIMU.begin ();
32+ CurieIMU.attachInterrupt (eventCallback);
33+
34+ // Increase Accelerometer range to allow detection of stronger taps (< 4g)
35+ CurieIMU.setAccelerometerRange (4 );
36+
37+ // Reduce threshold to allow detection of weaker taps (>= 750mg)
38+ CurieIMU.setDetectionThreshold (CURIE_IMU_DOUBLE_TAP, 750 ); // (750mg)
39+
40+ // Set the quite time window for 2 taps to be registered as a double-tap (Gap time between taps <= 1000 milliseconds)
41+ CurieIMU.setDetectionDuration (CURIE_IMU_DOUBLE_TAP, 1000 );
42+
43+ // Enable Double-Tap detection
44+ CurieIMU.interrupts (CURIE_IMU_DOUBLE_TAP);
45+
46+ Serial.println (" IMU initialization complete, waiting for events..." );
47+ }
48+
49+ void loop () {
50+ // nothing happens in the loop because all the action happens
51+ // in the callback function.
52+ }
53+
54+ static void eventCallback ()
55+ {
56+ if (CurieIMU.getInterruptStatus (CURIE_IMU_DOUBLE_TAP)) {
57+ if (CurieIMU.tapDetected (X_AXIS, NEGATIVE))
58+ Serial.println (" Double Tap detected on negative X-axis" );
59+ if (CurieIMU.tapDetected (X_AXIS, POSITIVE))
60+ Serial.println (" Double Tap detected on positive X-axis" );
61+ if (CurieIMU.tapDetected (Y_AXIS, NEGATIVE))
62+ Serial.println (" Double Tap detected on negative Y-axis" );
63+ if (CurieIMU.tapDetected (Y_AXIS, POSITIVE))
64+ Serial.println (" Double Tap detected on positive Y-axis" );
65+ if (CurieIMU.tapDetected (Z_AXIS, NEGATIVE))
66+ Serial.println (" Double Tap detected on negative Z-axis" );
67+ if (CurieIMU.tapDetected (Z_AXIS, POSITIVE))
68+ Serial.println (" Double Tap detected on positive Z-axis" );
69+ }
70+ }
0 commit comments