Acc 02: Free fall interruption
This example shows how to manage the free fall interruption.

Required Materials

1 x Waspmote 1 x MiniUSB wire

Notes

This example can be executed in Waspmote v12 and Waspmote v15

Code

1
/*
2
* ------ [ACC_02] Waspmote Accelerometer Free Fall Example --------
3
*
4
* Explanation: This example shows how to manage the free fall
5
* 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, Yuri Carmona
26
*/
27
28
void setup()
29
{
30
// open serial port
31
USB.ON();
32
USB.println(F("ACC_02 example"));
33
}
34
35
void loop()
36
{
37
///////////////////////////////////////////////
38
// 1. Starts accelerometer
39
///////////////////////////////////////////////
40
ACC.ON();
41
42
///////////////////////////////////////////////
43
// 2. Enable interruption: ACC Free Fall interruption
44
///////////////////////////////////////////////
45
ACC.setFF();
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: ACC Free Fall interrupt
57
// This is done to avoid new interruptions
58
///////////////////////////////////////////////
59
ACC.ON();
60
ACC.unsetFF();
61
62
USB.ON();
63
USB.println(F("Waspmote wakes up"));
64
65
///////////////////////////////////////////////
66
// 5. Check the interruption source
67
///////////////////////////////////////////////
68
// Only mandatory when multiple interruption
69
// sources are expected to be generated
70
if( intFlag & ACC_INT )
71
{
72
// clear interruption flag
73
intFlag &= ~(ACC_INT);
74
75
// print info
76
USB.ON();
77
USB.println(F("++++++++++++++++++++++++++++"));
78
USB.println(F("++ ACC interrupt detected ++"));
79
USB.println(F("++++++++++++++++++++++++++++"));
80
USB.println();
81
82
// blink LEDs
83
for(int i=0; i<10; i++)
84
{
85
Utils.blinkLEDs(50);
86
}
87
88
/*
89
* Insert your code here if more things needed
90
*/
91
92
}
93
94
///////////////////////////////////////////////////////////////////////
95
// 6. Clear interruption pin
96
///////////////////////////////////////////////////////////////////////
97
// This function is used to make sure the interruption pin is cleared
98
// if a non-captured interruption has been produced
99
PWR.clearInterruptionPin();
100
}
Copied!

Output

1
H#
2
ACC_02 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
Waspmote goes into sleep mode until the Accelerometer causes an interrupt
10
Waspmote wakes up
11
++++++++++++++++++++++++++++
12
++ ACC interrupt detected ++
13
++++++++++++++++++++++++++++
14
15
Waspmote goes into sleep mode until the Accelerometer causes an interrupt
Copied!
Last modified 1yr ago