This repository has been archived by the owner on Dec 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
INS Code.ino
66 lines (62 loc) · 2.78 KB
/
INS Code.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
#include <SparkFun_LIS331.h>
#include <Wire.h>
LIS331 xl;
void setup()
{
// put your setup code here, to run once:
pinMode(9,INPUT); // Interrupt pin input
Wire.begin();
xl.setI2CAddr(0x19); // This MUST be called BEFORE .begin() so
// .begin() can communicate with the chip
xl.begin(LIS331::USE_I2C); // Selects the bus to be used and sets
// the power up bit on the accelerometer.
// Also zeroes out all accelerometer
// registers that are user writable.
// This next section configures an interrupt. It will cause pin
// INT1 on the accelerometer to go high when the absolute value
// of the reading on the Z-axis exceeds a certain level for a
// certain number of samples.
xl.intSrcConfig(LIS331::INT_SRC, 1); // Select the source of the
// signal which appears on pin INT1. In
// this case, we want the corresponding
// interrupt's status to appear.
xl.setIntDuration(50, 1); // Number of samples a value must meet
// the interrupt condition before an
// interrupt signal is issued. At the
// default rate of 50Hz, this is one sec.
xl.setIntThreshold(2, 1); // Threshold for an interrupt. This is
// not actual counts, but rather, actual
// counts divided by 16.
xl.enableInterrupt(LIS331::Z_AXIS, LIS331::TRIG_ON_HIGH, 1, true);
// Enable the interrupt. Parameters indicate
// which axis to sample, when to trigger
// (in this case, when the absolute mag
// of the signal exceeds the threshold),
// which interrupt source we're configuring,
// and whether to enable (true) or disable
// (false) the interrupt.
Serial.begin(115200);
}
void loop()
{
static long loopTimer = 0;
int16_t x, y, z;
if (millis() - loopTimer > 1000)
{
loopTimer = millis();
xl.readAxes(x, y, z); // The readAxes() function transfers the
// current axis readings into the three
// parameter variables passed to it.
Serial.println(x);
Serial.println(y);
Serial.println(z);
Serial.println(xl.convertToG(6,x)); // The convertToG() function
Serial.println(xl.convertToG(6,y)); // accepts as parameters the
Serial.println(xl.convertToG(6,z)); // raw value and the current
Serial.println(" "); // maximum g-rating.
}
if (digitalRead(9) == HIGH)
{
Serial.println("Interrupt");
}
}