-
Notifications
You must be signed in to change notification settings - Fork 10
Open
Description
The following code works great if the device starts out flat. But if the device boots at an angle, it constantly prints "Interrupt pin is HIGH. OK". Any way to fix that so when the device is booted at an angle, the interrupt does not fire, but fires when the device is further moved?
#include <Wire.h>
#include "SparkFun_LIS2DH12.h"
SPARKFUN_LIS2DH12 accel;
int accelInterruptPin = 5;
void setup()
{
Serial.begin(115200);
delay(500);
Serial.println("SparkFun Accel Example");
Wire.begin();
if (!accel.begin(24))
{
Serial.println("Accelerometer not detected. Check address jumper and wiring. Freezing...");
while (1);
}
pinMode(accelInterruptPin, INPUT_PULLDOWN);
accel.setDataRate(LIS2DH12_POWER_DOWN); //Stop measurements
// Set INT_POLARITY to Active Low
accel.setIntPolarity(HIGH);
// Set INT1 interrupt
accel.setInt1IA1(true);
// Set INT1 threshold and duration for any movement detection
accel.setInt1Threshold(6); // Set threshold to the smallest value for any movement
accel.setInt1Duration(9); // Set a duration to filter out noise
// Clear the interrupt
while (accel.getInt1()) delay(10); // Reading int will clear it
// Set data rate and enable interrupts
accel.setDataRate(LIS2DH12_ODR_400Hz);
accel.setInt1(true); // Enable interrupts on INT1 pin
Serial.println("Begin Interrupt Scanning");
Serial.println("Detecting any movement...");
}
void loop()
{
// Check the interrupt pin
if (digitalRead(accelInterruptPin) == HIGH) {
if (accel.getInt1() == true) { // Reading int will clear it
Serial.println("Interrupt pin is HIGH. OK");
}
else {
Serial.println("Interrupt pin is HIGH. This shouldn't print");
}
} else {
Serial.println("Interrupt pin is LOW");
}
delay(200);
}
Metadata
Metadata
Assignees
Labels
No labels