title: Acceleration and deceleration for stepper motors
body: <p>I am having problems with a hard code example of accelerating a stepper motor. I can have the motor run at a constant speed but in order for it to start and not lose steps, I need an acceleration as it will move something relatively heavy. The code I have written does not seem to want to iterate the way it does without the additional code. The code is copied below in the void loop() section of the arduino code. </p>
  
  <pre><code>   `digitalWrite(dir, HIGH);
      for(int i=0; i &lt;= distance; i++){
        Serial.println(i);
        if(i&lt;1000){
          wait = 500 - (0.45*i);
        }
        else{
          wait = 50;
        }
        digitalWrite(pul, HIGH);
        delayMicroseconds(wait);
        digitalWrite(pul, LOW);
        delayMicroseconds(wait);
      }`
  </code></pre>
  
  <p>The program does not want to operate as written. The AccelStepper library is not a great option and this type of acceleration shouldn't be hard to add. I don't understand why this isn't working.</p>
  
  <p>I have added continue; after the if and else statements as well and that does not fix my problem.</p>
  
  <p>Also for decceleration my plan was to do the same in the opposite direction. </p>