Skip to content

Instantly share code, notes, and snippets.

@cat-haines
Created April 15, 2015 15:49
Show Gist options
  • Save cat-haines/77ca0912d2d44a1751bb to your computer and use it in GitHub Desktop.
Save cat-haines/77ca0912d2d44a1751bb to your computer and use it in GitHub Desktop.
Updated IMU example code.. now with interrupts
#require "lsm9ds0.class.nut:1.1"
/* RUNTIME START ------------------------------------------------------------ */
function xm_int1_cb() {
// you may want/need to debounce this function
if (xm_int1.read()) {
if (imu.clickIntActive()) {
server.log("Click interrupt on XM_INT1");
}
} else {
// interupt cleared, do nothing
}
}
xm_int1 <- hardware.pin2;
i2c <- hardware.i2c89;
i2c.configure(CLOCK_SPEED_400_KHZ);
xm_int1.configure(DIGITAL_IN_PULLDOWN, xm_int1_cb);
imu <- LSM9DS0(i2c);
imu.setEnable_A(1);
imu.setDatarate_A(100); // enable accel at 100 Hz
// set interrupt 1 polarity to active-high
// accel/mag interrupts are push-pull by default
// enable latching on interrupt 1 only
imu.setIntActivehigh_XM();
imu.setInt1LatchEn_XM(1);
// enable single-click interrupts
imu.setSnglclickIntEn_P1(1);
// set click detection threshold to 1.5 g
imu.setClickDetThs(1.5);
// set click window to 16 ms
imu.setClickTimeLimit(16);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment