-
-
Notifications
You must be signed in to change notification settings - Fork 284
/
Copy pathShockDetect.ino
73 lines (59 loc) · 2.5 KB
/
ShockDetect.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
* Copyright (c) 2016 Intel Corporation. All rights reserved.
* See the bottom of this file for the license terms.
*/
/*
This sketch example demonstrates how the BMI160 accelerometer on the
Intel(R) Curie(TM) module can be used to detect shocks or sudden movements
*/
#include "CurieIMU.h"
bool blinkState = false; // state of the LED
void setup() {
Serial.begin(9600); // initialize Serial communication
while(!Serial) ; // wait for serial port to connect..
/* Initialise the IMU */
CurieIMU.begin();
CurieIMU.attachInterrupt(eventCallback);
/* Enable Shock Detection */
CurieIMU.setDetectionThreshold(CURIE_IMU_SHOCK, 1500); // 1.5g = 1500 mg
CurieIMU.setDetectionDuration(CURIE_IMU_SHOCK, 50); // 50ms
CurieIMU.interrupts(CURIE_IMU_SHOCK);
Serial.println("IMU initialisation complete, waiting for events...");
}
void loop() {
// blink the LED in the main loop:
digitalWrite(13, blinkState);
blinkState = !blinkState;
delay(1000);
}
static void eventCallback(void)
{
if (CurieIMU.getInterruptStatus(CURIE_IMU_SHOCK)) {
if (CurieIMU.shockDetected(X_AXIS, POSITIVE))
Serial.println("Negative shock detected on X-axis");
if (CurieIMU.shockDetected(X_AXIS, NEGATIVE))
Serial.println("Positive shock detected on X-axis");
if (CurieIMU.shockDetected(Y_AXIS, POSITIVE))
Serial.println("Negative shock detected on Y-axis");
if (CurieIMU.shockDetected(Y_AXIS, NEGATIVE))
Serial.println("Positive shock detected on Y-axis");
if (CurieIMU.shockDetected(Z_AXIS, POSITIVE))
Serial.println("Negative shock detected on Z-axis");
if (CurieIMU.shockDetected(Z_AXIS, NEGATIVE))
Serial.println("Positive shock detected on Z-axis");
}
}
/*
Copyright (c) 2016 Intel Corporation. All rights reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/