28BYJ-48 5-Volt Stepper

I rewrote my original stepper test to utilize direct port manipulation. I hesitated in doing this until I was positive that writes to PORTB were not going to mess up the crystal on PB6 & PB7 - it does not. DO NOT TRY THIS SKETCH unless your setup is identical to the sketch. The PORTB writes only write to Digital pins 8-to-13. If you use different pins then you MUST rewrite the sketch. Read the other warning in the sketch. This sketch only been tested on an Arduino NANO.

// WARNING: USE AT YOUR OWN RISK!!!
// Do not use this script if your Arduino doesn't use a Atmega328 or Atmega168
// It is only been tested on an Arduino NANO
// This Arduino example demonstrates bidirectional operation of a 
// 28BYJ-48, which is readily available on eBay, using a ULN2003 
// interface board to drive the stepper.
//////////////////////////////
// The Atmega328p chips used on the Arduino board have three ports.
// We are interested in port B:
// We are using Arduino Digital bits 8-11, which map to Atmega328p PB0-PB3 
// B (digital pin 8 to 13)
// NOTE: as tested by anescient, there's no harm in writing to PORTB as long as DDRB[6:7] are 0
// Read: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1261361330
////////////////////////////////////////////////
// The speed and direction of the stepper motor is determined 
// by adjusting a 1k-ohm potentiometer connected to Arduino pin A2. 
// When the potentiometer is rotated fully counterclockwise, the motor 
// will rotate at full counterclockwise speed. As the potentiometer is 
// rotated clockwise, the motor will continue to slow down until is 
// reaches its minimum speed at the the potentiometer's midpoint value . 
// Once the potentiometer crosses its midpoint, the motor will reverse 
// direction. As the potentiometer is rotated further clockwise, the speed   
// of the motor will increase until it reaches its full clockwise rotation 
// speed when the potentiometer has been rotated fully clockwise.
////////////////////////////////////////////////

//declare variables for the motor pins
int motorPin1 = 8;	// Blue   - 28BYJ48 pin 1
int motorPin2 = 9;	// Pink   - 28BYJ48 pin 2
int motorPin3 = 10;	// Yellow - 28BYJ48 pin 3
int motorPin4 = 11;	// Orange - 28BYJ48 pin 4
                        // Red    - 28BYJ48 pin 5 (VCC)

int motorSpeed = 0;     //variable to set stepper speed
int potPin = 2; 	//potentiometer connected to A2
int potValue = 0; 	//variable to read A0 input


//////////////////////////////////////////////////////////////////////////////
void setup() {
  //declare the motor pins as outputs
  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);
  pinMode(motorPin3, OUTPUT);
  pinMode(motorPin4, OUTPUT);
  Serial.begin(9600);
}

//////////////////////////////////////////////////////////////////////////////
void loop(){

  potValue = analogRead(potPin);     // read the value of the potentiometer
  Serial.println(potValue);          // View full range from 0 - 1024 in Serial Monitor
  if (potValue < 535){               // if potentiometer reads 0 to 535 do this
    motorSpeed = (potValue/15 + 5);  //scale potValue to be useful for motor
    clockwise();                     //go to the ccw rotation function
  }
  else {                             //value of the potentiometer is 512 - 1024
    motorSpeed = ((1024-potValue)/15 + 5); //scale potValue for motor speed
    counterclockwise(); //go the the cw rotation function
  }
}

//////////////////////////////////////////////////////////////////////////////
//set pins to ULN2003 high in sequence from 1 to 4
//delay "motorSpeed" between each pin setting (to determine speed)

void counterclockwise (){
  // 1
  PORTB = 0b0001;
  delay(motorSpeed);
  // 2
  PORTB = 0b0011;
  delay(motorSpeed);
  // 3
  PORTB = 0b0010;
  delay(motorSpeed);
  // 4
  PORTB = 0b0110;
  delay(motorSpeed);
  // 5
  PORTB = 0b0100;
  delay(motorSpeed);
  // 6
  PORTB = 0b1100;
  delay(motorSpeed);
  // 7
  PORTB = 0b1000;
  delay(motorSpeed);
  // 8
  PORTB = 0b1001;
  delay(motorSpeed);
}

//////////////////////////////////////////////////////////////////////////////
//set pins to ULN2003 high in sequence from 4 to 1
//delay "motorSpeed" between each pin setting (to determine speed)

void clockwise(){
   // 1
   PORTB = 0b1000;
  delay(motorSpeed);
  // 2
  PORTB = 0b1100;
  delay(motorSpeed);
  // 3
  PORTB = 0b0100;
  delay(motorSpeed);
  // 4
  PORTB = 0b0110;
  delay(motorSpeed);
  // 5
  PORTB = 0b0010;
  delay(motorSpeed);
  // 6
  PORTB = 0b0011;
  delay(motorSpeed);
  // 7
  PORTB = 0b0001;
  delay(motorSpeed);
  // 8
  PORTB = 0b1001;
  delay(motorSpeed);
}

Now if I can determine the optimal "motorspeed" value then I can optimize the stepper's functionality.