Skip to content

Commit 20040d8

Browse files
committed
Fixed Wire and changed Interrupt function
1 parent f0d7fa2 commit 20040d8

File tree

1 file changed

+66
-63
lines changed

1 file changed

+66
-63
lines changed

Diff for: examples/Motion/Motion.ino

+66-63
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,81 @@
11
/****************************************************************************
2-
* Copyright (C) 2011 - 2014 Bosch Sensortec GmbH
3-
*
4-
* Motion.ino
5-
* Date: 2014/09/09
6-
* Revision: 2.0 $
7-
*
8-
* Usage: Example code of a game to demonstrate the Any motion
9-
* and No motion Interrupt features
10-
*
2+
Copyright (C) 2011 - 2014 Bosch Sensortec GmbH
3+
4+
Motion.ino
5+
Date: 2014/09/09
6+
Revision: 2.0 $
7+
8+
Usage: Example code of a game to demonstrate the Any motion
9+
and No motion Interrupt features
10+
1111
****************************************************************************
12-
/***************************************************************************
13-
* License:
14-
*
15-
* Redistribution and use in source and binary forms, with or without
16-
* modification, are permitted provided that the following conditions are met:
17-
*
18-
* Redistributions of source code must retain the above copyright
19-
* notice, this list of conditions and the following disclaimer.
20-
*
21-
* Redistributions in binary form must reproduce the above copyright
22-
* notice, this list of conditions and the following disclaimer in the
23-
* documentation and/or other materials provided with the distribution.
24-
*
25-
* Neither the name of the copyright holder nor the names of the
26-
* contributors may be used to endorse or promote products derived from
27-
* this software without specific prior written permission.
28-
*
29-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
30-
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
31-
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
32-
* DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
33-
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34-
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
35-
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
36-
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37-
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
38-
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
39-
*
40-
* The information provided is believed to be accurate and reliable.
41-
* The copyright holder assumes no responsibility for the consequences of use
42-
* of such information nor for any infringement of patents or
43-
* other rights of third parties which may result from its use.
44-
* No license is granted by implication or otherwise under any patent or
45-
* patent rights of the copyright holder.
12+
/***************************************************************************
13+
License:
14+
15+
Redistribution and use in source and binary forms, with or without
16+
modification, are permitted provided that the following conditions are met:
17+
18+
Redistributions of source code must retain the above copyright
19+
notice, this list of conditions and the following disclaimer.
20+
21+
Redistributions in binary form must reproduce the above copyright
22+
notice, this list of conditions and the following disclaimer in the
23+
documentation and/or other materials provided with the distribution.
24+
25+
Neither the name of the copyright holder nor the names of the
26+
contributors may be used to endorse or promote products derived from
27+
this software without specific prior written permission.
28+
29+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
30+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
31+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
32+
DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
33+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
35+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
36+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
38+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
39+
40+
The information provided is believed to be accurate and reliable.
41+
The copyright holder assumes no responsibility for the consequences of use
42+
of such information nor for any infringement of patents or
43+
other rights of third parties which may result from its use.
44+
No license is granted by implication or otherwise under any patent or
45+
patent rights of the copyright holder.
4646
*/
4747

48-
#include "NineAxesMotion.h" //Contains the bridge code between the API and the Arduino Environment
48+
#include "NineAxesMotion.h" //Contains the bridge code between the API and the Arduino Environment
4949
#include <Wire.h>
5050

51-
NineAxesMotion mySensor; //Object that for the sensor
52-
bool intDetected = false; //Flag to indicate if an interrupt was detected
53-
int threshold = 5; //At a Range of 4g, the threshold is set at 39.05mg or 0.3830m/s2. This Range is the default for NDOF Mode
54-
int duration = 1; //At a filter Bandwidth of 62.5Hz, the duration is 8ms. This Bandwidth is the default for NDOF Mode
55-
bool anyMotion = true; //To know which interrupt was triggered
51+
NineAxesMotion mySensor; //Object that for the sensor
52+
bool intDetected = false; //Flag to indicate if an interrupt was detected
53+
int threshold = 5; //At a Range of 4g, the threshold is set at 39.05mg or 0.3830m/s2. This Range is the default for NDOF Mode
54+
int duration = 1; //At a filter Bandwidth of 62.5Hz, the duration is 8ms. This Bandwidth is the default for NDOF Mode
55+
bool anyMotion = true; //To know which interrupt was triggered
56+
57+
int InterruptPin = 2; // Pin D2 is connected to the INT LED
5658

5759
void setup() //This code is executed once
5860
{
5961
//Peripheral Initialization
60-
Serial.begin(115200); //Initialize the Serial Port to view information on the Serial Monitor
61-
I2C.begin(); //Initialize I2C communication to the let the library communicate with the sensor.
62+
Serial.begin(9600); //Initialize the Serial Port to view information on the Serial Monitor
63+
Wire.begin(); //Initialize I2C communication to the let the library communicate with the sensor.
6264
//Sensor Initialization
6365
Serial.println("Please wait. Initialization in process.");
64-
mySensor.initSensor(); //The I2C Address can be changed here inside this function in the library
65-
mySensor.setOperationMode(OPERATION_MODE_NDOF); //Can be configured to other operation modes as desired
66-
mySensor.setUpdateMode(MANUAL); //The default is AUTO. Changing to manual requires calling the relevant update functions prior to calling the read functions
66+
mySensor.initSensor(); //The I2C Address can be changed here inside this function in the library
67+
mySensor.setOperationMode(OPERATION_MODE_NDOF); //Can be configured to other operation modes as desired
68+
mySensor.setUpdateMode(MANUAL); //The default is AUTO. Changing to manual requires calling the relevant update functions prior to calling the read functions
6769
//Setting to MANUAL requires lesser reads to the sensor
6870

69-
attachInterrupt(INT_PIN, motionISR, RISING); //Attach the interrupt to the Interrupt Service Routine for a Rising Edge. Change the interrupt pin depending on the board
71+
72+
attachInterrupt(digitalPinToInterrupt(InterruptPin), motionISR, RISING); //Attach the interrupt to the Interrupt Service Routine for a Rising Edge. Change the interrupt pin depending on the board
7073

7174
//Setup the initial interrupt to trigger at No Motion
7275
mySensor.resetInterrupt();
7376
mySensor.enableSlowNoMotion(threshold, duration, NO_MOTION);
7477
anyMotion = false;
75-
mySensor.accelInterrupts(ENABLE, ENABLE, ENABLE); //Accelerometer interrupts can be triggered from all 3 axes
78+
mySensor.accelInterrupts(ENABLE, ENABLE, ENABLE); //Accelerometer interrupts can be triggered from all 3 axes
7679
Serial.println("This is a game to test how steady you can move an object with one hand. \nKeep the device on a table and mark 2 points.");
7780
Serial.println("Move the Device from one place to another without triggering the Any Motion Interrupt.\n\n");
7881
delay(1000); //Delay for the player(s) to read
@@ -88,18 +91,18 @@ void loop() //This code is looped forever
8891
{
8992
Serial.println("You moved!! Try again. Keep the Device at one place.\n");
9093
intDetected = false;
91-
mySensor.resetInterrupt(); //Reset the interrupt line
92-
mySensor.disableAnyMotion(); //Disable the Any motion interrupt
93-
mySensor.enableSlowNoMotion(threshold, duration, NO_MOTION); //Enable the No motion interrupt (can also use the Slow motion instead)
94+
mySensor.resetInterrupt(); //Reset the interrupt line
95+
mySensor.disableAnyMotion(); //Disable the Any motion interrupt
96+
mySensor.enableSlowNoMotion(threshold, duration, NO_MOTION); //Enable the No motion interrupt (can also use the Slow motion instead)
9497
anyMotion = false;
9598
}
9699
else
97100
{
98101
Serial.println("Device is not moving. You may start again.\n\n\n");
99102
intDetected = false;
100-
mySensor.resetInterrupt(); //Reset the interrupt line
101-
mySensor.disableSlowNoMotion(); //Disable the Slow or No motion interrupt
102-
mySensor.enableAnyMotion(threshold, duration); //Enable the Any motion interrupt
103+
mySensor.resetInterrupt(); //Reset the interrupt line
104+
mySensor.disableSlowNoMotion(); //Disable the Slow or No motion interrupt
105+
mySensor.enableAnyMotion(threshold, duration); //Enable the Any motion interrupt
103106
anyMotion = true;
104107
}
105108
}
@@ -109,4 +112,4 @@ void loop() //This code is looped forever
109112
void motionISR()
110113
{
111114
intDetected = true;
112-
}
115+
}

0 commit comments

Comments
 (0)