Acc 07: 6D position
This example shows how to manage the 6D Position recognition interruption

Required Materials

1 x Waspmote 1 x MiniUSB wire

Notes

- When the 6D position interrupt is activated, a change in position of Waspmote will generate an interruption and wake up Waspmote - This example can be executed in Waspmote v12 and Waspmote v15

Code

1
/*
2
* ------ [ACC_07] Waspmote Accelerometer 6D Position Example--------
3
*
4
* Explanation: This example shows how to manage the 6D Position
5
* recognition interruption
6
*
7
* Copyright (C) 2016 Libelium Comunicaciones Distribuidas S.L.
8
* http://www.libelium.com
9
*
10
* This program is free software: you can redistribute it and/or modify
11
* it under the terms of the GNU General Public License as published by
12
* the Free Software Foundation, either version 3 of the License, or
13
* (at your option) any later version.
14
*
15
* This program is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
* GNU General Public License for more details.
19
*
20
* You should have received a copy of the GNU General Public License
21
* along with this program. If not, see <http://www.gnu.org/licenses/>.
22
*
23
* Version: 3.0
24
* Design: David Gascón
25
* Implementation: Marcos Yarza
26
*/
27
28
void setup()
29
{
30
// open serial port
31
USB.ON();
32
USB.println(F("ACC_07 example"));
33
}
34
35
void loop()
36
{
37
///////////////////////////////////////////////
38
// 1. Starts accelerometer
39
///////////////////////////////////////////////
40
ACC.ON();
41
42
///////////////////////////////////////////////
43
// 2. Enable interruption: 6D Position
44
///////////////////////////////////////////////
45
ACC.set6DPosition();
46
47
///////////////////////////////////////////////
48
// 3. Set low-power consumption state
49
///////////////////////////////////////////////
50
USB.println(F("Waspmote goes into sleep mode until the Accelerometer causes an interrupt"));
51
PWR.sleep(ALL_OFF);
52
53
// Interruption event happened
54
55
///////////////////////////////////////////////
56
// 4. Disable interruption: 6D Position
57
// This is done to avoid new interruptions
58
///////////////////////////////////////////////
59
ACC.ON();
60
ACC.unset6DPosition();
61
62
USB.ON();
63
USB.println(F("Waspmote wakes up"));
64
65
///////////////////////////////////////////////
66
// 5. Check the interruption source
67
///////////////////////////////////////////////
68
if( intFlag & ACC_INT )
69
{
70
// print info
71
USB.ON();
72
USB.println(F("++++++++++++++++++++++++++++"));
73
USB.println(F("++ ACC interrupt detected ++"));
74
USB.println(F("++++++++++++++++++++++++++++"));
75
USB.println();
76
77
// blink LEDs
78
for(int i=0; i<10; i++)
79
{
80
Utils.blinkLEDs(50);
81
}
82
83
USB.println(F("++++++++++++++++++++++++++++++++++++++++++++++++"));
84
USB.println(F("++ 6D Movement Recognition interrupt detected ++"));
85
int aux = ACC.readRegister(INT1_SRC);
86
USB.print("++ Position: ");
87
if (aux & ZHIE) USB.print("+Z");
88
if (aux & ZLIE) USB.print("-Z");
89
if (aux & YHIE) USB.print("+Y");
90
if (aux & YLIE) USB.print("-Y");
91
if (aux & XHIE) USB.print("+X");
92
if (aux & XLIE) USB.print("-X");
93
USB.println(F(" ++"));
94
USB.println(F("++++++++++++++++++++++++++++++++++++++++++++++++"));
95
USB.println();
96
97
98
/*
99
* Insert your code here if more things needed
100
*/
101
102
}
103
104
///////////////////////////////////////////////////////////////////////
105
// 6. Clear 'intFlag'
106
///////////////////////////////////////////////////////////////////////
107
// This is mandatory, if not this interruption will not be deleted and
108
// Waspmote could think in the future that a not existing interruption arrived
109
clearIntFlag();
110
111
///////////////////////////////////////////////////////////////////////
112
// 7. Clear interruption pin
113
///////////////////////////////////////////////////////////////////////
114
// This function is used to make sure the interruption pin is cleared
115
// if a non-captured interruption has been produced
116
PWR.clearInterruptionPin();
117
}
Copied!

Output

1
H#
2
ACC_07 example
3
Waspmote goes into sleep mode until the Accelerometer causes an interrupt
4
Waspmote wakes up
5
++++++++++++++++++++++++++++
6
++ ACC interrupt detected ++
7
++++++++++++++++++++++++++++
8
9
++++++++++++++++++++++++++++++++++++++++++++++++
10
++ 6D Movement Recognition interrupt detected ++
11
++ Position: ++
12
++++++++++++++++++++++++++++++++++++++++++++++++
13
14
Waspmote goes into sleep mode until the Accelerometer causes an interrupt
15
Waspmote wakes up
16
++++++++++++++++++++++++++++
17
++ ACC interrupt detected ++
18
++++++++++++++++++++++++++++
19
20
++++++++++++++++++++++++++++++++++++++++++++++++
21
++ 6D Movement Recognition interrupt detected ++
22
++ Position: ++
23
++++++++++++++++++++++++++++++++++++++++++++++++
24
25
Waspmote goes into sleep mode until the Accelerometer causes an interrupt
Copied!
Last modified 1yr ago