     }
     else
     {
-	  // Brake
-      digitalWrite(HbridgeLogicPin1, HIGH);
-      digitalWrite(HbridgeLogicPin2, HIGH);
+      // Brake ?
+      digitalWrite(HbridgeLogicPin1, LOW);
+      digitalWrite(HbridgeLogicPin2, LOW);
     }
 	// \todo: add an input to enable manual rotation of the motor
   }
-  delay(minTime_ms);
-
-  sensorValue = analogRead(analogInPin);
-  if (sensorValue < 10)
-  { 
-    // Motor is free to move to enable manual control
-    digitalWrite(HbridgeEnablePin, LOW);
-  }
-  else
-  { 
-    digitalWrite(HbridgeEnablePin, HIGH);
-  }
-  if (false==isSerialControl)
-  {
-    alphaSigned = 2*((sensorValue-sensorValueMin)/(sensorValueMax - sensorValueMin)-0.5);  
-  }
-  alpha = max(fabs(alphaSigned), deadBand);
-  alpha = min(alpha, 1);
-    if (alphaSigned>fabs(deadBand))
-  {
-    digitalWrite(HbridgeLogicPin1, HIGH);
-    digitalWrite(HbridgeLogicPin2, LOW);
-  }
-  else 
-  {
-    if (alphaSigned<-fabs(deadBand))
-    {
-      digitalWrite(HbridgeLogicPin1, LOW);
-      digitalWrite(HbridgeLogicPin2, HIGH);
-    }
-    else
-    {
-      digitalWrite(HbridgeLogicPin1, LOW);
-      digitalWrite(HbridgeLogicPin2, LOW);
-    }
-  }
-  double initialTime = millis();
-  double elapsedTime_ms = millis() - initialTime;
-  while (elapsedTime_ms < minTime_ms/alpha*(1-alpha)-minTime_ms)
-  {
-    digitalWrite(HbridgeEnablePin, LOW);
-    delay(minTime_ms);
-    sensorValue = analogRead(analogInPin);
-    if (sensorValue < 10)
-    { 
-    // Motor is free to move to enable manual control
-      digitalWrite(HbridgeEnablePin, LOW);
-    }
-    else
-    { 
-      digitalWrite(HbridgeEnablePin, HIGH);
-    }
-//    Serial.print("sensorValue = " );                       
-//    Serial.println(sensorValue);   
-  if (false==isSerialControl)
-  {
-    alphaSigned = 2*((sensorValue-sensorValueMin)/(sensorValueMax - sensorValueMin)-0.5);  
-  }
-  //    Serial.print("alphaSigned = " );                       
-//    Serial.println(alphaSigned);   
-    alpha = max(fabs(alphaSigned), deadBand);
-    alpha = min(alpha, 1);
-    if (alphaSigned>fabs(deadBand))
-    {
-      digitalWrite(HbridgeLogicPin1, HIGH);
-      digitalWrite(HbridgeLogicPin2, LOW);
-    }
-    else 
-    {
-      if (alphaSigned<-fabs(deadBand))
-      {
-        digitalWrite(HbridgeLogicPin1, LOW);
-        digitalWrite(HbridgeLogicPin2, HIGH);
-      }
-      else
-      {
-        digitalWrite(HbridgeLogicPin1, LOW);
-        digitalWrite(HbridgeLogicPin2, LOW);
-      }
-    }
-//    Serial.print("alpha = " );                       
-//    Serial.println(alpha);   
-    elapsedTime_ms = millis() - initialTime;
-//    Serial.print("elapsedTime_ms = " );                       
-//    Serial.println(elapsedTime_ms);    
-  }
-  digitalWrite(HbridgeEnablePin, LOW);
-  delay(fabs(minTime_ms/alpha*(1-alpha)- elapsedTime_ms));
-
-//  // print the results to the serial monitor:
-//  Serial.print("alphaManual = " );                       
-//  Serial.print(alphaSigned);      
-//  Serial.print("\t alphaUsed = ");      
-//  Serial.println(alphaSigned);   
+  return alpha;
 }
 
 

This file ensures the control of a continuous current motor and gearbox through an H-bridge.
A Pulse Width Modulation is used. The algorithm uses varying cycle frequency to allow control at low rotation speed.
Due to minimum quantity of energy to make the motor turn, the motor will not turn smoothly at low speed.
There is now feedback nor stall control on speed, so the output rotation speed may depend on load torque.
The motor is controlled through a parameter alpha which is signed and vary from -1 to -1.
This parameter can be set thanks to a an analog voltage (set through a potentiometer for example) or sent over serial connection
The analog voltage is taken by default.
If the analog voltage is not zero, the motor is left free of moving
To start the serial control send "i" in a serial monitor

To stop the serial control send "o".
There is not guarantee that there is a linear relationship between alpha and the rotation speed
*/

// Minimal time to have motor starting at maximum voltage. This will depend on the motor used
// Try to reduce to get a smooth motion
