   return sqrt(pow(from.lat - to.lat, 2) + pow(from.lng - to.lng, 2));
 }
 
+// Stores a value for the sliding window average
+void put_avg(double val) {
+  avg_buf[avg_buf_pos] = val;
+  avg_buf_pos = (avg_buf_pos + 1) % avg_count;
+}
+
+// Gets the average of all stored values
+double get_avg() {
+  double avg = 0;
+  for (int i = 0; i < avg_count; i++) {
+    avg += avg_buf[i] / avg_count;
+  }
+  return avg;
+}
+
+// Called when the GPS has a new location
 void on_new_gps(double lat, double lng) {
   current_loc.lat = lat;
   current_loc.lng = lng;

// ETA in milliseconds. If negative, we're traveling away from current_dest
double eta_time = 0;

Destination dests[] = {
  {"Test", {0.0, 10.0}},
  {"Home", {45.022884, -93.244983}},
  {"Work", {44.989136, -93.250454}},
};

// Change current_dest to change the distance and eta
Location current_dest = dests[0].loc;

  delta_dist = current_dist - last_dist;

  eta_time = -delta_time * current_dist / delta_dist;
  put_avg(eta_time / 1000);
}

// Used for simulating GPS data
unsigned long update_at = 0;

// Start serial
void setup() {
  Serial.begin(9600);
}

// Fake GPS data and print calculated values
void loop() {
  if (millis() >= update_at) {
    update_at = millis() + 250;
