Sketch to vary stepper speed with 10k pot will not verify

Hi, I have a project where I need stepper motor to vibrate. I have a working sketch that does it pretty well, but I wanted to do a new one where I can vary the speed with a pot to find the best harmonic vibration.
I found a sketch online which I modified to suit my needs using the “AccelStepper” library for the first time, when I try to verify it on the last line I get:

exit status 1 ‘stepper1’ was not defined in this scope

#include <AccelStepper.h>
#include <MultiStepper.h>



// Define the stepper and the pins it will use
#define STEP_PIN                2
#define DIRECTION_PIN           7

// Define input button pin
#define  LEFT_PIN  4

// Define our analog pot input pin
#define  SPEED_PIN 0

// Define our maximum and minimum speed in steps per second (scale pot to these)
#define  MAX_SPEED 500
#define  MIN_SPEED 0.1

void setup() {
  // The only AccelStepper value we have to set here is the max speed, which is higher than we'll ever go
  stepper1.setMaxSpeed(10000.0);

  // Set up the button input, with pullup
  pinMode(LEFT_PIN, INPUT_PULLUP);

}

void loop() {
  static float current_speed = 0.0;         // Holds current motor speed in steps/second
  static int analog_read_counter = 1000;    // Counts down to 0 to fire analog read
  static char sign = 0;                     // Holds -1, 1 or 0 to turn the motor on/off and control direction
  static int analog_value = 0;              // Holds raw analog value.

  // If the switch is pushed down (low), set the sign value appropriately
  if (digitalRead(LEFT_PIN) == 0) {
    sign = 1;
  }


  // We only want to read the pot every so often (because it takes a long time we don't
  // want to do it every time through the main loop).
  if (analog_read_counter > 0) {
    analog_read_counter--;
  }
  else {
    analog_read_counter = 3000;
    // Now read the pot (from 0 to 1023)
    analog_value = analogRead(SPEED_PIN);
    // Give the stepper a chance to step if it needs to
    stepper1.runSpeed();
    //  And scale the pot's value from min to max speeds
    current_speed = sign * (((analog_value / 1023.0) * (MAX_SPEED - MIN_SPEED)) + MIN_SPEED);
    // Update the stepper to run at this new speed
    stepper1.setSpeed(current_speed);
  }

  // This will run the stepper at a constant speed
  stepper1.runSpeed();
}

I have searched the term with no results, as I have never used AccelStepper before I am a little lost on troubleshooting, any help would be appreciated.

So why don't you declare the stepper?

Danois90: So why don't you declare the stepper?

OK, I thought that maybe this was something within AccelStepper

I am very new to this, am I right in thinking that the line that causes the problem is where the program looks at a value in the bracket and if it is the same as it was last time there is no speed change?

I have searched "Declare the stepper"no results,

Would that be as simple as inserting "#define stepper1" or is there more to it than that?

You might want to read a tutorial to get the some basic understanding of what you are doing :)

Have you looked at the AccelStepper examples that come with the library ?

I spent a lot of time reading and looking at examples. I eventually found something to help.

Turns out that the fact that I had defined the stepper motor was the problem, I redid the sketch and allowed AccelStepper to define the stepper and it worked.

rog8811:
Turns out that the fact that I had defined the stepper motor was the problem, I redid the sketch and allowed AccelStepper to define the stepper and it worked.

That sounds as if you don’t have a proper understanding of the situation. Please post the working code.

…R