controlling stepper motor steps with R3 shield

HI, I wonder if someone could tel me how I can integrate these two sketches please. Ive tried many configurations with no success. What i am trying to do is control the number of steps using an UNO and R3 motor shield. The motor knob example will not drive the motor shield, and the other one runs the stepper perfectly but is only adjustable by altering the value of steps and revs.
Any help would be very gratefully received as I'm very new to sketch writing :blush:

Include the Stepper Library
#include <Stepper.h>

// Map our pins to constants to make things easier to keep track of
const int pwmA = 3;
const int pwmB = 11;
const int brakeA = 9;
const int brakeB = 8;
const int dirA = 12;
const int dirB = 13;

// The amount of steps for a full revolution of your motor.
// 360 / stepAngle
const int STEPS = 480;

// Initialize the Stepper class
Stepper myStepper(STEPS, dirA, dirB);

void setup() {
// Set the RPM of the motor
myStepper.setSpeed(20);

// Turn on pulse width modulation
pinMode(pwmA, OUTPUT);
digitalWrite(pwmA, HIGH);
pinMode(pwmB, OUTPUT);
digitalWrite(pwmB, HIGH);

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

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

void loop() {
// Move the motor X amount of steps
myStepper.step(STEPS);
Serial.println(STEPS);
// Pause
delay(2000);

// Move the motor X amount of steps the other way
myStepper.step(-STEPS);
Serial.println(-STEPS);
// Pause
delay(2000);
}

  • MotorKnob
  • A stepper motor follows the turns of a potentiometer
  • (or other sensor) on analog input 0.
  • Stepper - Arduino Reference
  • This example code is in the public domain.
    */

#include <Stepper.h>

// change this to the number of steps on your motor
#define STEPS 100

// create an instance of the stepper class, specifying
// the number of steps of the motor and the pins it's
// attached to
Stepper stepper(STEPS, 8, 9, 10, 11);

// the previous reading from the analog input
int previous = 0;

void setup()
{
// set the speed of the motor to 30 RPMs
stepper.setSpeed(30);
}

void loop()
{
// get the sensor value
int val = analogRead(0);

// move a number of steps equal to the change in the
// sensor reading
stepper.step(val - previous);

// remember the previous value of the sensor
previous = val;
}