 byte spectrum[9];
 
 
-#define SIZE 1024
-#define SLICE 32
+#define SIZE 512
+#define SLICE 16
 
 byte huge[SIZE];
 long energy[SIZE/SLICE];
 int p = 0;
-long t;
+volatile long t;
 long start;
 long last_beat;
 long beat_length;

    sumEnergy/=SIZE;
    energy[(SIZE/SLICE)-1] = newEnergy;
    long diff = millis()-t;
    if (newEnergy > 1.3 * sumEnergy && diff > .9*beat_length) {
      if (offBeat) {
        float newBPM = 60000/(float)diff;
        bpm = bpm*.9 + newBPM*.1;
        beat_length = beat_length*.9 + diff*.1;
        t = millis();  
      }
      offBeat = false;
    } 
    else {
      offBeat = true;
    }
  }

}


  if (!offBeat && !sentBeat) {
    spectrum[8] = 1;
    sentBeat = true;
 //   Serial.println("!!!!!!!!!");
  } else {
    spectrum[8] = 0;
    sentBeat = false;
 //   Serial.print(beat_length);
 //   Serial.print("\t");
 //   Serial.println(bpm);
  }
  Wire.write(spectrum, 9);
}


