 //    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))
+    if (alphaSigned>fabs(deadBand))
     {
-      digitalWrite(HbridgeLogicPin1, LOW);
-      digitalWrite(HbridgeLogicPin2, HIGH);
-    }
-    else
-    {
-      digitalWrite(HbridgeLogicPin1, LOW);
+      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;

void loop()
{
  digitalWrite(HbridgeEnablePin, HIGH);
  double minTime_ms = 30;//Minimal time to have motor starting at maximum voltage
  // read the analog in value:
  double sensorValueMin = 255;//0
  double sensorValueMax = 767;//1023
  double deadBand = 0.05; // Should not be zero
  sensorValue = analogRead(analogInPin);
  //alphaSigned = 2*((sensorValue-sensorValueMin)/(sensorValueMax - sensorValueMin)-0.5);  
  double alpha = max(fabs(alphaSigned), deadBand);
  alpha = min(alpha, 1);
  if (alphaSigned>fabs(deadBand))
  {
    digitalWrite(HbridgeLogicPin1, HIGH);
    digitalWrite(HbridgeLogicPin2, LOW);
  }

  {
    if (alphaSigned<-fabs(deadBand))
    {
	  // Backward rotation
      digitalWrite(HbridgeLogicPin1, LOW);
      digitalWrite(HbridgeLogicPin2, HIGH);
    }
    else
    {
	  // Brake
      digitalWrite(HbridgeLogicPin1, LOW);
      digitalWrite(HbridgeLogicPin2, LOW);
    }
	// \todo: add an input to enable manual rotation of the motor
  }
  delay(minTime_ms);

