   
   //initialize the variables we're linked to
   Input = 0;
-  Setpoint = 600;
+  Setpoint = 500;
 
   //turn the PID on
   myPID.SetMode(AUTOMATIC);
+  myPID.SetOutputLimits(89, 255);
+  myPID.SetSampleTime(sample_interval-1); // ensure a pid compute for every speed sample
 
   //Serial.println("Begin");
       

      if (sample == LOW) {
        // Just seen a black bit.
        ms_per_int = count * sample_interval;
        count = 0;
        //Serial.println(ms_per_int);
        
        ms_per_int = constrain(ms_per_int, 100, 700);
        
        // Convert to byte value for processing for now
        speed_motor_left = map(ms_per_int, 100, 700, 700, 100);
        //speed_motor_left = ms_per_int;
        Input = speed_motor_left;
        //Serial.print(" : "); Serial.print(speed_motor_left);
        //Serial.print(" - "); Serial.println(Input);
      }
      
    }
    count++; // Up the sample count
    
    /*
    speed_requested = analogRead(PIN_POT) / 4;
    if (speed_requested < 75) {
      // Can't go slower than this
      speed_requested = 0; 
    }
    */
    //Serial.println(speed_requested);
    
    //pid-related code
    myPID.Compute();
    
    
    pwm_motor_left = Output;
    pwm_motor_left = constrain(pwm_motor_left, 100, 180);
    //if (pwm_motor_left < 90) pwm_motor_left = 90;
    analogWrite(PIN_MOTOR_LEFT, pwm_motor_left);
    
    /*
    // Send it to the motor if changed
    if (pwm_motor_left != speed_requested) {
      pwm_motor_left = speed_requested;
      
      //pwm_motor_left = map(Output, 0, 1000, 0, 255);
      if (pwm_motor_left < 75) pwm_motor_left = 0;
      analogWrite(PIN_MOTOR_LEFT, pwm_motor_left);
    }
    */
    
  }
  

  if (millis()>serialTime) {
    SerialReceive();
    SerialSend();
    serialTime+=250;
  }
  

