AccellStepper help

Total NOOBY here so go easy on my ego.

Question 1) I would like my steppers to start out with an acceleration specified every time they are called so they don’t stall.
They way I have it , they only have the acceleration rate the first time called. After the first call they start out full speed every time. I have tried moving the following commands all over the place but it doesn’t seem to matter.

verticalstepper.setMaxSpeed(3000); // set verticalstepper max speed
verticalstepper.setAcceleration(50.0); // set stepper accelleration lower # + slower ramp up

Question 2) I have taken the following command out of my code since it didn’t do anything:

stepper.stop(); // Stop as fast as possible: sets new target

It seems like if you meet a condition and no longer call stepper.run() it stops the motor?

Please help enlighten me on the correct usage or suggest something else that will accelerate up to top speed every time called.
As you can see I’m not a programmer but this is working for me so far.
Thanks for any help.

Ferny

//April 2014 Big Dipper state machine by Ferny
// a state machine that lcd outputs case when changed
#include <AccelStepper.h>
#include <LiquidCrystal.h>
#include <LCDKeypad.h>
#include <Wire.h>

//Setup LCD pins ENB, R/W is GND, RS, D4, D5, D6, D7
LiquidCrystal lcd(50, 52, 42, 44, 46, 48);//Pins used to control LCD 8bit

AccelStepper verticalstepper(1, 40, 36);
AccelStepper rotarystepper(1, 41, 37);

const int homevertical = 0; //set case # to name
const int downpos = 1; //set case # to name 
const int homerotary = 2; //set case # to name
const int rotate = 3; //set case # to name
const int defaultcase = 4; //set case # to name
const int rotarysensorpin = 22;  // sensor input pin #
const int uppersensorpin = 24;  // sensor input pin #
const int startpin = 26;// was lowersensorpin = 28;  // sensor input pin #
int led =  13;    // the number of the LED pin

// the current state we're in at any given time. We want to start in
// "off", so we set the variable to sOff when we declare it.
int currentState = defaultcase;
// we need to have somewhere to go when we leave sOff, so let's pick
int nextState = defaultcase;
// our on/off switch
//int onOffPin = 2;
int startpressed = 0;
int upsensorstate = 0;
int rotarysensorstate = 0;

void setup()
{
  pinMode(startpin, INPUT); //define sensor pin direction was lowersensorpin
  pinMode(uppersensorpin, INPUT); //define sensor pin direction
  pinMode(rotarysensorpin, INPUT); //define sensor pin direction
  pinMode(led, OUTPUT); //define LED pin direction
  //verticalstepper.setMaxSpeed(3000); // set stepper top speed
  //verticalstepper.setAcceleration(50.0); // set stepper accelleration lower # + slower ramp up
  rotarystepper.setMaxSpeed(3000); // set stepper top speed
  rotarystepper.setAcceleration(10.0); // set stepper accelleration lower # + slower ramp up
  lcd.begin(16, 2);//setup LCD panel 16 character 2 line LCD Shield
  lcd.clear(); //clear LCD panel
  lcd.setCursor(0,0); //set position 0 line 0
  lcd.print("FERNY CASE ");  //set 1st line LCD max 16 characters or spaces
  lcd.setCursor(0,1); //set position 0 line 1
  lcd.print("EXAMPLE "); //set 2nd line LCD max 16 characters or spaces
  delay(2000); //wait to see message before clearing LCD panel
  lcd.clear(); //clear LCD panel
  //delay(2000);
  // if we didn't set the initial state when we created the variable,
  // we'd do it here. The initial state is "off" or "start" in most
  // state machines, but if you only have active/on states, pick an
  // appropriate starting state.
  // currentState = sOff;

}
void loop()
{

  switch(currentState) 
  {
  case defaultcase:
    {
      startpressed = digitalRead(startpin);
      lcd.setCursor(0,0); //position 0 line 0
      lcd.print("defaultcase");  //1st line LCD max 16 characters or spaces   
      //wait for switched input to start cases
      delay(100);
      if (startpressed == HIGH) {     
        digitalWrite(led, HIGH); //turn LED on:  
        currentState = defaultcase; 
        nextState = homevertical; //change state
      } 
      else {
        digitalWrite(led, LOW ); // turn LED off:
        currentState = nextState;
        nextState = defaultcase; //change state
        lcd.clear();
      }
      break;

    case homevertical:
      {
        verticalstepper.setMaxSpeed(3000); // set verticalstepper max speed
        verticalstepper.setAcceleration(50.0); // set stepper accelleration lower # + slower ramp up  
        upsensorstate = 0; //define upsensorstate to variable
        //lcd.clear();
        lcd.clear(); //clear the LCDpanel
        lcd.setCursor(0,0); //position 0 top line 0
        lcd.print("homevertical");  //print 1st line LCD max 16 characters
        {
          while (digitalRead(uppersensorpin) == LOW) { //move motor while uppersensorpin is not blocked stop when it is
            verticalstepper.move(1000); //move enough steps to hit uppersensor 
            verticalstepper.run();   
            //{
            //    verticalstepper.stop(); // Stop as fast as possible: sets new target
            //}
            verticalstepper.setAcceleration(50.0); // set stepper accelleration lower # + slower ramp up
            //delay(1000);
            currentState = nextState;
            nextState = homerotary;
          }
        }
      }
      break;

    case downpos:
      {
        lcd.setCursor(0,0); //position 0 line 0
        lcd.print("downpos");  //1st line LCD max 16 characters or spaces
        delay(1000);
        lcd.clear();
        currentState = nextState;
        nextState = rotate;
      }
      break;

    case homerotary:
      {
        lcd.clear();
        lcd.setCursor(0,0); //position 0 line 0
        lcd.print("homerotary");  //1st line LCD max 16 characters or spaces  
        rotarystepper.setMaxSpeed(3000); // set stepper top speed
        rotarystepper.setAcceleration(50.0); // set stepper accelleration lower # + slower ramp up  
        rotarysensorstate = 0;
        {
          while (digitalRead(rotarysensorpin) == LOW) {//move rotory stepper until it sees rotaryhome sensor then stop
            rotarystepper.move(1000); // move rotarystepper enough steps to see rotarysensorsensor 
            rotarystepper.run();   
            currentState = nextState;
            nextState = rotate;
          }
        }
      }
      break;

    case rotate:
      {
        lcd.setCursor(0,0); //position 0 line 0
        lcd.print("rotate");  //1st line LCD max 16 characters or spaces 
        delay(1000);
        lcd.clear();
        currentState = nextState;
        nextState = defaultcase;
      }
      break;


    }
  }
}

If you can be bothered to use Tools + Auto Format to make that code readable, I can then be bothered to read it.

Colors aren't coming through but it did indent. I just learned something. Thanks Paul

From the documentation the run() method must be called frequently in the main loop, at least once per step for each motor that is moving - failure to do this means it will fail to do acceleration properly. There is no great penalty in calling run() for every motor every time through loop() - so do this...