Stepper Motor Control with A4988 and Arduino

Hi,

I am currently trying to control a stepper Motor with Arduino. So far so good. Here is my problem: I have two codes very similar, one of them works, the other doesnt. Could it be that the Arduinos processing time is giving the stepper controller problems?

Here are the two codes:

Working:

const int stepPin = 3;
const int dirPin = 4;
const int potPin = A5;

int potInput;
int delayTime;

void setup() {
  Serial.begin(9600);
  Serial.println("Serial connection established at a baudrate of 9600");
  pinMode(stepPin,OUTPUT);
  pinMode(dirPin,OUTPUT);
  digitalWrite(dirPin,HIGH);
}

void loop() {
  potInput = analogRead(potPin);
  delayTime = map(potInput, 0, 1023, 100, 5000);
  digitalWrite(stepPin,HIGH);
  delayMicroseconds(delayTime);
  digitalWrite(stepPin,LOW);
  delayMicroseconds(delayTime);
}

Not Working:

const int stepPin = 3;
const int dirPin = 4;
const int potPin = A5;

int potInput;
int potInputProcessed;
int posFeedback;
int delayTime;

void setup() {
  Serial.begin(9600);
  Serial.println("Serial connection established at a baudrate of 9600");
  pinMode(stepPin,OUTPUT);
  pinMode(dirPin,OUTPUT);
  digitalWrite(dirPin,HIGH);
}

void loop() {
  potInput = analogRead(potPin);
  potInputProcessed = map(potInput, 0, 1023, -100, 100);
  delayTime = map(potInput, 0, 1023, 100, 5000);
  digitalWrite(stepPin,HIGH);
  delayMicroseconds(delayTime);
  digitalWrite(stepPin,LOW);
  delayMicroseconds(delayTime);
  posFeedback = posFeedback + potInputProcessed;
  Serial.println(posFeedback);
}

Thank you very much!

What do you mean by doesn't work?

What happens if you comment out all the extra lines in the non-working program?

...R Stepper Motor Basics Simple Stepper Code

Serial.println(posFeedback);

Serial is S. L. O. W.

The first few prints go into the buffer so they go fast. But once it is full, it must wait thousands of microseconds for each character to send.