   digitalWrite(rightMotorPin2, HIGH);
 }
 
-boolean ultraCheck(){
+long ultraMesure() {
   /* Utilisation du capteur Ultrason HC-SR04 */
 
-long lecture_echo;
-long cm;
+  long lecture_echo;
+  long cm;
 
   digitalWrite(ultraTrig, HIGH);
   delayMicroseconds(10);
   digitalWrite(ultraTrig, LOW);
   lecture_echo = pulseIn(ultraEcho, HIGH);
-  cm = lecture_echo / 58;
-  Serial.print("Distancem : ");
-  Serial.print(cm);
-  Serial.println("cm");
-  delay(10);
-  }
+  cm = lecture_echo/29;
+
+  return cm;
+}
+
+void ultraCheck(int ultraBuffer[10]) {
+  long cm = 0;
+  for (int i = 0; i < 10; i++) {
+    cm += ultraBuffer[i] / 10;
+  }
+
+  Serial.println(cm);
+}
 
 void stopRight() {
   digitalWrite(rightMotorPin1, LOW);

      break;
    case 'b':
    case 'B': // Back direction
    Serial.println("Revert revert revert!");
      setLeftSpeed( (serialInput[1] * 100 + serialInput[2] * 10 + serialInput[3]) * -1);
      setRightSpeed( (serialInput[1] * 100 + serialInput[2] * 10 + serialInput[3]) * -1);

      break;
    case 's':
    case 'S': // Starting block
    Serial.println("Lock'n'load!");
      prepareToStart();
      break;
    case 'g':
    case 'G': // GO !!!
    Serial.println("Smooth splosh");
      smoothSploch();
      break;
    case 'W':
    case 'w': // Emergy stop
     Serial.println("Emergency Stop!!");
               stopMotors();
      break;

    default:


void loop() {
  // TODO Script to win here ;)
  int i = ultraCompteur % 10;
  int first_i = (ultraCompteur + 1) % 10;
  ultraBuffer[i] = ultraMesure();
  ultraSum += ultraBuffer[i];
  ultraSum -= ultraBuffer[first_i];

if (ultraSum/10 < 20){
  digitalWrite(13,HIGH);
  } else {
    digitalWrite(13,LOW);
    }
  ultraCompteur++;


}

// Serial
