Skip to content

Commit cdd2989

Browse files
jysholarBrian Baltz
jysholar
authored and
Brian Baltz
committed
CurieIMU tap/double example, JIRA-508
1 parent 434fcd4 commit cdd2989

File tree

2 files changed

+80
-13
lines changed

2 files changed

+80
-13
lines changed

libraries/CurieIMU/examples/TapDetect/TapDetect.ino

+10-13
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,10 @@ void setup() {
3737
// Reduce threshold to allow detection of weaker taps (>= 750mg)
3838
CurieIMU.setDetectionThreshold(CURIE_IMU_TAP, 750); // (750mg)
3939

40-
// Set the time window for 2 taps to be registered as a double-tap (<= 250 milliseconds)
41-
CurieIMU.setDetectionDuration(CURIE_IMU_DOUBLE_TAP, 250);
42-
4340
// Enable Double-Tap detection
44-
CurieIMU.interrupts(CURIE_IMU_DOUBLE_TAP);
41+
CurieIMU.interrupts(CURIE_IMU_TAP);
4542

46-
Serial.println("IMU initialisation complete, waiting for events...");
43+
Serial.println("IMU initialization complete, waiting for events...");
4744
}
4845

4946
void loop() {
@@ -53,18 +50,18 @@ void loop() {
5350

5451
static void eventCallback()
5552
{
56-
if (CurieIMU.getInterruptStatus(CURIE_IMU_DOUBLE_TAP)) {
53+
if (CurieIMU.getInterruptStatus(CURIE_IMU_TAP)) {
5754
if (CurieIMU.tapDetected(X_AXIS, NEGATIVE))
58-
Serial.println("Double Tap detected on negative X-axis");
55+
Serial.println("Tap detected on negative X-axis");
5956
if (CurieIMU.tapDetected(X_AXIS, POSITIVE))
60-
Serial.println("Double Tap detected on positive X-axis");
57+
Serial.println("Tap detected on positive X-axis");
6158
if (CurieIMU.tapDetected(Y_AXIS, NEGATIVE))
62-
Serial.println("Double Tap detected on negative Y-axis");
59+
Serial.println("Tap detected on negative Y-axis");
6360
if (CurieIMU.tapDetected(Y_AXIS, POSITIVE))
64-
Serial.println("Double Tap detected on positive Y-axis");
61+
Serial.println("Tap detected on positive Y-axis");
6562
if (CurieIMU.tapDetected(Z_AXIS, NEGATIVE))
66-
Serial.println("Double Tap detected on negative Z-axis");
63+
Serial.println("Tap detected on negative Z-axis");
6764
if (CurieIMU.tapDetected(Z_AXIS, POSITIVE))
68-
Serial.println("Double Tap detected on positive Z-axis");
65+
Serial.println("Tap detected on positive Z-axis");
6966
}
70-
}
67+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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

Comments
 (0)