 void dof_setup() {
   if(!lsm.begin()) { while(1); }
 
-  /* Setup the sensor gain and integration time */
+  // Setup the sensor gain and integration time
   configureSensor();
   
   // Set a max and min value to not do anything
   // calibrate(accel.acceleration.x, accel.acceleration.y);
-  
   sensors_event_t accel, mag, gyro, temp;
   lsm.getEvent(&accel, &mag, &gyro, &temp);  
 }

#include <Adafruit_LSM9DS0.h>
#include "Adafruit_MPR121.h"

/* This driver uses the Adafruit unified sensor library (Adafruit_Sensor),
   which provides a common 'type' for sensor data and some helper functions.

   To use this driver you will also need to download the Adafruit_Sensor
   library and include it in your libraries folder.

   You should also assign a unique ID to this sensor for use with
   the Adafruit Sensor API so that you can identify this particular
   sensor in any data logs, etc.  To assign a unique ID, simply
   provide an appropriate value in the constructor below (12345
   is used by default in this example).

   Connections (For default I2C)
   ===========
   Connect SCL to analog 5
   Connect SDA to analog 4
   Connect VDD to 5V DC
   Connect GROUND to common ground

   History
   =======
   2014/JULY/25  - First version (KTOWN)
*/

/* Assign a unique base ID for this sensor */

// 9DOF
Adafruit_LSM9DS0 lsm = Adafruit_LSM9DS0(1005);  // Use I2C, ID #1000
#define LSM9DS0_XM_CS 10
#define LSM9DS0_GYRO_CS 9
#define LSM9DS0_SCLK 13
#define LSM9DS0_MISO 12
#define LSM9DS0_MOSI 11

float xNormal = -3.0;
float yNormal = 1;
float xRange[] = {0,0};
float yRange[] = {0,0};

// MPR121
// You can have up to 4 on one i2c bus but one is enough for testing!
Adafruit_MPR121 cap = Adafruit_MPR121();

uint16_t lasttouched = 0;
uint16_t currtouched = 0;

// Configures the gain and integration time for the TSL2561

void configureSensor(void) {
  // 1.) Set the accelerometer range
  //lsm.setupAccel(lsm.LSM9DS0_ACCELRANGE_2G);

void dof_loop() {
  /* Get a new sensor event */
  sensors_event_t accel, mag, gyro, temp;
  lsm.getEvent(&accel, &mag, &gyro, &temp);

  float mx, my = 0.0;
  float accelX = clamp(accel.acceleration.x, accelMin, accelMax);
  float accelY = clamp(accel.acceleration.y, accelMin, accelMax);

  if (accel.acceleration.x > xRange[1] || accel.acceleration.x < xRange[0]) {
    my = map(accelX, accelMin, accelMax, outMax, outMin);
    mx = map(accelY, accelMin, accelMax, outMax, outMin);
  }
  else if (accel.acceleration.y > yRange[1] || accel.acceleration.y < yRange[0]) {
    my = map(accelX, accelMin, accelMax, outMax, outMin);
    mx = map(accelY, accelMin, accelMax, outMax, outMin);
  }

  Mouse.move(mx, my, 0);
  delay(5);
}

void mpr_loop() {
  // Get the currently touched pads
  currtouched = cap.touched();
  checkTouch();
  // reset our state
  lasttouched = currtouched;
}

void checkTouch() {
  for (uint8_t i=0; i < 12; i++) {
    // it if *is* touched and *wasnt* touched before, alert!
    if ( (currtouched & _BV(i)) && !(lasttouched & _BV(i)) ) touchHandler(i);

    // if it *was* touched and now *isnt*, alert!
    if ( !(currtouched & _BV(i)) && (lasttouched & _BV(i)) ) releaseHandler(i);
  } 
}

void touchHandler(int id) {
  Serial.print(id); Serial.println(" released");
}

void releaseHandler(int id) {
  Serial.print(id); Serial.println(" touched");
}

void calibrate(float x, float y) {
