     Serial.println("");
   }
 
-  mag.getEvent(&mag_event);
-  if (dof.magGetOrientation(SENSOR_AXIS_Z, &mag_event, &orientation))
-  {
-    dtostrf(orientation.heading, 5, 2 , buf);
-    sprintf(buffer, "^%s~%s~%s~", "GYRO", "heading", buf);
-    Serial.write(buffer);
-  }
-  if (debug) {
-    Serial.println("");
-  }
+  dtostrf(compassTotal/(double)compassCount, 5, 2 , buf);
+  compassCount = 0;
+  compassTotal = 0;
+  sprintf(buffer, "^%s~%s~%s~", "GYRO", "heading", buf);
+  Serial.write(buffer);
 }
 
 void setup() {

Adafruit_9DOF                dof   = Adafruit_9DOF();
Adafruit_LSM303_Mag_Unified   mag   = Adafruit_LSM303_Mag_Unified(30302);
int i;

void printData() {
  sensors_vec_t orientation;
  sensors_event_t mag_event;
  int dif;
  blocks = -1;
  char buffer[100];

f#include <Adafruit_Sensor.h>
#include <Adafruit_LSM303_U.h>
#include <Adafruit_9DOF.h>
#include <Adafruit_L3GD20_U.h>
