   digitalWrite(controlPin, HIGH);
   digitalWrite(servoPowerPin, HIGH);
   delay(100);
+
+  for(int c = 0; c < 5; c++) { //Initialize gyro average buffer beforehand because time is limited
+  sensors_event_t event; 
+  gyro.getEvent(&event);
+  gyroData[0] = event.gyro.x;
+  gyroData[1] = event.gyro.y;
+  gyroData[2] = event.gyro.z;
+  gyroZBuffer2[c] = gyroData[2];
+  }
+  
 }
 
 

float baroAltBuffer[5] = {0, 0, 0, 0, 0};
float gyroZBuffer[7] = {0, 0, 0, 0, 0, 0, 0}; //The other values are arbitrary; this one is used in Simpsons Rule, so it MUST BE ODD!
float timeBuffer[7] = {0, 0, 0, 0, 0, 0, 0}; //Must equal the size of gyroZBuffer; used for the same calculations.

float accelAverage;
float baroAverage; //Averages of the above buffer values


  baroAverage /= 5;
  baroAverage = baroAverage - startAlt; //Have to compare the average to the ground, not sea level

  if (flightState == burnout) { //Keep track of rotations once we transition to the burnout stage
    if (!endRollFlag) {
      /*
         This section functions stepwise. Once the two buffers are full, the algorithm performs numerical
         integration, increments rollCounter, and flushes the buffers before starting over.
      */
      if (timeBuffer[6] < 1) { //If the buffers are not yet full; avoiding == 0 because it's a floating point

        for (int c = 0; c < 6; c++) {
          timeBuffer[6 - c] = timeBuffer[5 - c];
          gyroZBuffer[6 - c] = gyroZBuffer[5 - c];
        }
        timeBuffer[0] = millis();
        gyroZBuffer[0] = gyroData[2] - GYRO_DRIFT_FACTOR; //Again, this buffer should be up-to-date

      }

      else { //Once the buffers are full, perform the integration!

        float deltaT = (timeBuffer[0] - timeBuffer[6]) / 18; //Note: the average is technically /6, but since Simpson's Rule adds a /3 anyways, it's just more efficient to combine them
        float simpsonSum = gyroZBuffer[0] + gyroZBuffer[6];
        simpsonSum = simpsonSum + 4 * (gyroZBuffer[1] + gyroZBuffer[3] + gyroZBuffer[5]);
        simpsonSum = simpsonSum + 2 * (gyroZBuffer[2] + gyroZBuffer[4]);
        simpsonSum = simpsonSum * deltaT / 1000; //Hooray for numerical integration! Should look into whether there's a more efficient way to perform Simpson's rule here.

        rotationCounter = rotationCounter + (simpsonSum / 6.28318531) * SIMPSON_SCALE_FACTOR; //Convert from radians to revolutions and increment the counter!

        for (int c = 0; c < 7; c++) {
          timeBuffer[c] = 0;
          gyroZBuffer[c] = 0; //Don't forget to clear the buffers for the next step!
        }

      }
    }
    else {
      gyroAverage = 0;

      for (int c = 0; c < 4; c++) {
        gyroZBuffer2[4 - c] = gyroZBuffer2[3 - c];
      }
      gyroZBuffer2[0] = gyroData[2];

      for (int c = 0; c < 5; c++) {
        gyroAverage = gyroAverage + gyroZBuffer2[c];
      }
      gyroAverage /= 5;
    }
  }
}

