Wanting to add an accel and decel function to a Motor Controller

Robin2:
Rather than use the value from the potentiometer directly, use it as a max or min setting and use another variable to control the speed of the motor.

Then at whatever intervals seem reasonable (maybe every 100 millisecs) adjust the motor speed variable up or down in steps until it matches the value from the potentiometer. Something like this

byte adjPWM = 5; // just a guess for illustration

unsigned long changeIntervalMillis = 100;
if (millis() - prevChangeMillis >= changeIntervalMillis) {
  prevChangeMillis += changeIntervalMillis;
  if (motorPWM > potPWM) {
     motorPWM -= adjPWM;
  }
  else if (motorPWM < potPWM) {
     motorPWM += adjPWM;
  }
  analogWrite(motorPin, motorPWM;
}




...R

Woohoo! :slight_smile:

This worked flawlessly! Thank You!! I knew I had to be over thinking it. Other than making adjustments for variable names and moving some stuff around it was just what i needed and now i understand the millis function much better. Thank you for posting this. This community is priceless!