     default: return -1; // other button
   }
 }
+
+void test_speed(int angle) {
+  for (int i = 0; i < 20; ++i) {
+    myservo.write(90 - angle);
+    delay(300);
+    myservo.write(90 + angle);
+    delay(300);
+  }
+}

  digitalWrite(LED_BUILTIN, HIGH);
  digitalWrite(is_downbeat ? RED : BLUE, HIGH);
  digitalWrite(is_downbeat ? LED_1 : LED_2, HIGH);
  delay(is_downbeat ? 200 : 150);
  digitalWrite(LED_BUILTIN, LOW);
  digitalWrite(is_downbeat ? RED : BLUE, LOW);
  digitalWrite(is_downbeat ? LED_1 : LED_2, LOW);

}

void switch_servo() {
  int step = 5;
  int sign = servo_count ? -1 : 1;
  int interval = 60000 / current_bpm;
  int delay_ms = interval * 4 / 5 / SERVO_MAX_ANGLE * 2 / step;

  //delay(max(0, interval - 300));
  for (int i = -SERVO_MAX_ANGLE; i <= SERVO_MAX_ANGLE; i += step) {
    myservo.write(90 + sign * i);
    if (i != SERVO_MAX_ANGLE) delay(delay_ms);
  }
  servo_count = !servo_count;
}
