Stepper motor control with switches and POT on arduino motor shield... HELP!!

Hi all.

This is my very first Arduino project, I've been learning for a week or so now. I'm building a camera slider for timelapse photography.

I'm having a hard time finding good examples for stepper motor control, but this one DOES work, so I started adapting from it:

#include <Stepper.h>
 
 const int stepsPerRevolution = 200;  // change this to fit the number of steps per revolution
                          // for your motor
 
 // initialize the stepper library on the motor shield
 Stepper myStepper(stepsPerRevolution, 12,13);     
 
 // give the motor control pins names:
 const int pwmA = 3;
 const int pwmB = 11;
 const int brakeA = 9;
 const int brakeB = 8;
 const int dirA = 12;
 const int dirB = 13;
 
 int x = 0;
void setup() {
 Serial.begin(9600);
 // set the PWM and brake pins so that the direction pins  // can be used to control the motor:
pinMode(pwmA, OUTPUT);
 pinMode(pwmB, OUTPUT);
 pinMode(brakeA, OUTPUT);
 pinMode(brakeB, OUTPUT);
 digitalWrite(pwmA, HIGH);
 digitalWrite(pwmB, HIGH);
 digitalWrite(brakeA, LOW);
 digitalWrite(brakeB, LOW);
 
 // initialize the serial port:
 Serial.begin(9600);
 // set the motor speed (for multiple steps only):
 myStepper.setSpeed(50);
 }

 
 void loop() {
 
  myStepper.step(200);
    delay(2000);
  myStepper.step(200);
    delay(2000);



 }

I have added a decent amount. My goal is to have a power switch, a HI/LO speed switch, an LED indicator for power, and a POT to control speed AND direction (ultimately -> mapped such that values below ~512 will be reverse and above ~512 will be forward motion.)

SO. Now it's not doing anything really, just a little stutter step. I THINK it's a timing issue, like my loop isn't taking into account for functions becoming active or whatever...
I think the biggest clue is that my LED is not even responding to my first IF statement, which it did in another basic test I wrote.

// Include the Stepper Library
#include <Stepper.h>
// Include the Servo Library for FUTURE
#include <Servo.h>

Servo myservo;               // servo object for future articulation


// map control pins
const int pwmA = 3;
const int pwmB = 11;
const int brakeA = 9;
const int brakeB = 8;
const int dirA = 12;
const int dirB = 13;
const int offSwitch = 2;     // switch to turn power off to motor - in series with limit switch
const int LEDpin = 4;        // power status LED
const int potIn = A0;        // analog signal from pot for speed control
const int speedSwitch = 7;   // switch for HIGH/LOW speed control


// variables
int STEPS = 200;             // steps in 1 full rotation (1.8 degrees)
int powerVar = 0;            // status for power switch
int speedVar = 0;            // status for speed switch
int inVal = 0;               // variable for mapping PWM to stepper
int outVal = 0;              // variable for default (off) setting
int mapSpeed = 0;            // variable for the mapped speed value

// Initialize stepper
Stepper myStepper(STEPS, dirA, dirB);

void setup() {

  // initialize output pins
  pinMode(pwmA, OUTPUT);
  digitalWrite(pwmA, HIGH);
  pinMode(pwmB, OUTPUT);
  digitalWrite(pwmB, HIGH);
  
  // initialize status pins
  pinMode (offSwitch, INPUT);
  pinMode (LEDpin, OUTPUT);
  pinMode (speedSwitch, INPUT);

  // Turn off the brakes
  pinMode(brakeA, OUTPUT);
  digitalWrite(brakeA, LOW);
  pinMode(brakeB, OUTPUT);
  digitalWrite(brakeB, LOW);

  // Log some shit
  Serial.begin(9600);
}

void loop() {
  
  // read the potentiometer value
  inVal = analogRead (potIn);
  
  // read power status
  powerVar = digitalRead (offSwitch);
  
  // read speed switch
  speedVar = digitalRead (speedSwitch);
  
  
  // check if the power is ON (HIGH)
  // if HIGH, then continue to check speed status
  // else, no motion
  if (powerVar == HIGH)
  {
  // Turn on LED
  digitalWrite (LEDpin, HIGH);
  
    // check speed status HI is (HIGH)
        if (speedVar == HIGH)
        {
          // map inVar to high speed
          mapSpeed = map (inVal,0,1023,1,30);
          
          // set speed
          myStepper.setSpeed (mapSpeed);
          
          // move (STEPS)
          myStepper.step (STEPS);
          Serial.println (STEPS);
          
         }
        
        if (speedVar == LOW) 
        {
         // map inVar to low speed
         mapSpeed = map (inVal,0,1023,1,5);
         
         // set speed
         myStepper.setSpeed (mapSpeed);
         
         // move (STEPS)
         myStepper.step (STEPS);
         Serial.println (STEPS);
        }
        
  else {
   myStepper.step (0);
   digitalWrite (LEDpin, LOW);
        }
  } 
    
delay (10);

}

Any help is HUGELY APPRECIATED!!!! :slight_smile: :slight_smile: :slight_smile:

Note: I understand the speed mapping don't work as I want them to, I just wanted to get it moving, then I would figure out the proper way to deal with the forward/reverse thing.