-
-
Notifications
You must be signed in to change notification settings - Fork 284
/
Copy pathFreeFallDetect.ino
68 lines (53 loc) · 2.19 KB
/
FreeFallDetect.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
/*
Copyright (c) 2016 Intel Corporation. All rights reserved.
See the bottom of this file for license terms.
*/
/*
This sketch example demonstrates how the BMI160 accelerometer on the
Intel(R) Curie(TM) module can be used to detect free fall events
*/
#include "CurieIMU.h"
bool blinkState = false; // state of the LED
unsigned long loopTime = 0; // get the time since program started
unsigned long interruptsTime = 0; // get the time when free fall event is detected
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 Free Fall Detection */
CurieIMU.setDetectionThreshold(CURIE_IMU_FREEFALL, 1000); // 1g=1000mg
CurieIMU.setDetectionDuration(CURIE_IMU_FREEFALL, 50); // 50ms
CurieIMU.interrupts(CURIE_IMU_FREEFALL);
Serial.println("IMU initialisation complete, waiting for events...");
}
void loop() {
// if free fall event is detected in 1000ms, LED will be turned up
loopTime = millis();
if(abs(loopTime -interruptsTime) < 1000 )
blinkState = true;
else
blinkState = false;
digitalWrite(13, blinkState);
}
static void eventCallback(){
if (CurieIMU.getInterruptStatus(CURIE_IMU_FREEFALL)) {
Serial.println("free fall detected! ");
interruptsTime = millis();
}
}
/*
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
*/