Need coding help with Rotary Encoder / Uno / Stepping motor

I've tried searching but I honestly, I'm really confused with the many projects search is turning up with tidbits of information that I can't make heads or tails of.

I purchased an Uno, Rotary Encoder, Ring LED Bargraph, RGB Ring encoder breakout, with a stepping motor (sparkfun ROB-09238).

I got the assembly down.

What I need - I'm wanting fairly good control of my motor to where it will move in sync with the rotary encoder, but I want to put a limit on how far I can turn the motor. For example; if I turn the knob from 0 to 400 degrees it will go, but if I try to go past 400 degrees I want the motor to return to 40 degree. Reason I need this is because I will have a small camera mounted on the stepping motor with a power cable and I don't want to wrap it around too many times.

I'm really intrigued by this board and will hopefully learn something from this without pulling out too much hair.

Impact9:
What I need - I'm wanting fairly good control of my motor to where it will move in sync with the rotary encoder, but I want to put a limit on how far I can turn the motor. For example; if I turn the knob from 0 to 400 degrees it will go, but if I try to go past 400 degrees I want the motor to return to 40 degree. Reason I need this is because I will have a small camera mounted on the stepping motor with a power cable and I don't want to wrap it around too many times.

Try something like this:

if (angle >= 400){
   angle = angle - 360
}

Or something similar, using the number of steps the motor takes. You'll need a variable to hold the count of steps, incrementing it for clockwise steps and decrementing it for anticlockwise steps. Then test it before any change to see if the change will go over the limit in either direction. If it does, then step the motor through 360 degrees in the opposite direction before applying the change.

I finally got everything wired up. I've followed these sources:

RGB Ringcoder - Sample code from Funspark (http://dlnmh9ip6v2uc.cloudfront.net/datasheets/BreakoutBoards/RGB_Ringcoder_Example.ino) both code and wiring.
Using a Rotary Encoder wiring/code (http://bildr.org/2012/08/rotary-encoder-arduino/)
Easydriver Code (http://bildr.org/2011/06/easydriver/)

This is the encoder I'm using - https://www.sparkfun.com/products/10982 with their recommended RGB Ringcoder.

I had to use Pins 0 and 1 on the Uno for the Easydriver since the RGB Ringcoder/encoder used Pins 2 & 3 according to Bildr guide the encoder has to go to Pins 2 & 3. I don't know if using pins 0/1 is okay or not. All the other pins are in use with the RGB Ringcoder except pin 4,1,0.

Working - Easydriver LED 5v is on. The RGB Ringcoder appears to be working correctly as far as illumination goes and it moves with encoder rotation.

Issues - I don't know if I'm doing this right either. I started the Arduino software, copied the code for the Encoder then created a new tab for both the Ringcoder, Encoder, and Easydriver. I had to rename the void setup and void loop sections in each table. From there everything uploaded fine. But the stepping motor (https://www.sparkfun.com/products/9238) moves a quarter turn on upload but will not respond to dial turns.

Being a complete noob at this isn't helping. :~

Here’s the compressed / merged code of the sources. I did this by putting the void setup and void loop in the same sections. Again need someone with more experiance than me to check this over. Issue with this is the RGBCoder breakout nor the encoder is showing any response.

#define ROTATION_SPEED 3
#define ENCODER_POSITION_MAX  (256 >> (ROTATION_SPEED - 1)) - 1
#define ENCODER_POSITION_MIN  0
#define DIR_PIN 0
#define STEP_PIN 1

int aPin = 3;
int bPin = 2;
int redPin = 5;
int bluPin = 6;
int grnPin = 9;
int swhPin = 7;
int enPin = 13;
int latchPin = 12;
int clkPin = 11;
int clrPin = 10;
int datPin = 8;

signed int encoderPosition;

enum ledCounter {RED = 0, BLUE = 1, GREEN = 2, NONE = 3};
byte ledCount = RED;
byte ledValue[3] = {255, 255, 255};
byte ledPins[3] = {redPin, bluPin, grnPin};

//these pins can not be changed 2/3 are special pins
int encoderPin1 = 2;
int encoderPin2 = 3;

volatile int lastEncoded = 0;
volatile long encoderValue = 0;

long lastencoderValue = 0;

int lastMSB = 0;
int lastLSB = 0;

void setup()
{
  pinMode(aPin, INPUT); 
  digitalWrite(aPin, HIGH);
  pinMode(bPin, INPUT);
  digitalWrite(bPin, HIGH);
  
  noInterrupts();
  attachInterrupt(0, readEncoder, CHANGE);
  attachInterrupt(1, readEncoder, CHANGE);
  
  pinMode(swhPin, INPUT);
  digitalWrite(swhPin, LOW);
  pinMode(redPin, OUTPUT);
  analogWrite(redPin, ledValue[RED]);
  pinMode(grnPin, OUTPUT);
  analogWrite(grnPin, ledValue[GREEN]);
  pinMode(bluPin, OUTPUT);
  analogWrite(bluPin, ledValue[BLUE]);
  
  pinMode(enPin, OUTPUT);  
  digitalWrite(enPin, LOW);  
  pinMode(latchPin, OUTPUT);
  digitalWrite(latchPin, LOW);
  pinMode(clkPin, OUTPUT);
  digitalWrite(clkPin, LOW);
  pinMode(clrPin, OUTPUT);
  digitalWrite(clrPin, HIGH);
  pinMode(datPin, OUTPUT);
  digitalWrite(datPin, LOW);
  
  digitalWrite(latchPin, LOW);
  shiftOut16(0x0000);
  digitalWrite(latchPin, HIGH);
    
  interrupts(); 
  
    pinMode(DIR_PIN, OUTPUT); 
  pinMode(STEP_PIN, OUTPUT); 
  
    Serial.begin (9600);

  pinMode(encoderPin1, INPUT); 
  pinMode(encoderPin2, INPUT);

  digitalWrite(encoderPin1, HIGH);
  digitalWrite(encoderPin2, HIGH);

  attachInterrupt(0, updateEncoder, CHANGE); 
  attachInterrupt(1, updateEncoder, CHANGE);
} 

void loop()
{
    if (digitalRead(swhPin) == HIGH)
  {
        if (ledCount == NONE)
      ledCount = RED;
    else
      ledCount++;
      
       while(digitalRead(swhPin) == HIGH)
      ;
  }
  
    ledRingFiller(ROTATION_SPEED);
  
  if (ledCount != NONE)
  {
        ledValue[ledCount] = 255 - (encoderPosition * ROTATION_SPEED);
    analogWrite(ledPins[ledCount], ledValue[ledCount]);
  }
}

void ledRingFiller(byte rotationSpeed)
{
  unsigned int ledShift = 0;
  unsigned int ledOutput = 0;
  if (encoderPosition != 0)
  {
    ledShift = encoderPosition & (0xFF >> (rotationSpeed-1));
    ledShift /= 0x10>>(rotationSpeed-1);
    for (int i=ledShift; i>=0; i--)
      ledOutput |= 1<<i;
  }
  
  digitalWrite(latchPin, LOW);
  shiftOut16(ledOutput);
  digitalWrite(latchPin, HIGH);
}

void ledRingFollower(byte rotationSpeed)
{

  unsigned int ledShift = 0;
  unsigned int ledOutput = 0;
    if (encoderPosition != 0)
  {

    ledShift = encoderPosition & (0xFF >> (rotationSpeed-1));
    ledShift /= 0x10>>(rotationSpeed-1);
    ledOutput = 1 << ledShift;
  }
  
  digitalWrite(latchPin, LOW);
  shiftOut16(ledOutput);
  digitalWrite(latchPin, HIGH);
}

void shiftOut16(uint16_t data)
{
  byte datamsb;
  byte datalsb;
  datamsb = (data&0xFF00)>>8;
  datalsb = data & 0xFF;
    shiftOut(datPin, clkPin, MSBFIRST, datamsb);
    shiftOut(datPin, clkPin, MSBFIRST, datalsb);
}

void readEncoder()
{
  noInterrupts();
  delayMicroseconds(5000);
  int8_t enc_states[] = {0,-1,1,0,1,0,0,-1,-1,0,0,1,0,1,-1,0};
  static uint8_t oldEncoderState = 0;
  static uint8_t newEncoderState = 0;
  newEncoderState = (digitalRead(bPin)<<1) | (digitalRead(aPin));
  
  oldEncoderState <<= 2;
  oldEncoderState &= 0xC0;
  oldEncoderState |= newEncoderState;
  encoderPosition += enc_states[oldEncoderState];
  #ifndef CONTINUOUS
 
    if (encoderPosition > ENCODER_POSITION_MAX)
      encoderPosition = ENCODER_POSITION_MAX;
       else if (encoderPosition < ENCODER_POSITION_MIN)
      encoderPosition = ENCODER_POSITION_MIN;
  #endif
  
  interrupts();
  
  rotateDeg(360, 1); 
  delay(1000);

  rotateDeg(-360, .1);
  delay(1000); 

  rotate(1600, .5); 
  delay(1000); 

  rotate(-1600, .25);
  delay(1000); 
}

void rotate(int steps, float speed){ 
    int dir = (steps > 0)? HIGH:LOW;
  steps = abs(steps);

  digitalWrite(DIR_PIN,dir); 

  float usDelay = (1/speed) * 70;

  for(int i=0; i < steps; i++){ 
    digitalWrite(STEP_PIN, HIGH); 
    delayMicroseconds(usDelay); 

    digitalWrite(STEP_PIN, LOW); 
    delayMicroseconds(usDelay); 
  } 
} 

void rotateDeg(float deg, float speed){ 
    int dir = (deg > 0)? HIGH:LOW;
  digitalWrite(DIR_PIN,dir); 

  int steps = abs(deg)*(1/0.225);
  float usDelay = (1/speed) * 70;

  for(int i=0; i < steps; i++){ 
    digitalWrite(STEP_PIN, HIGH); 
    delayMicroseconds(usDelay); 

    digitalWrite(STEP_PIN, LOW); 
    delayMicroseconds(usDelay); 
  } 
   
  Serial.println(encoderValue);
  delay(1000); 
}


void updateEncoder(){
  int MSB = digitalRead(encoderPin1);
  int LSB = digitalRead(encoderPin2);

  int encoded = (MSB << 1) |LSB;
  int sum  = (lastEncoded << 2) | encoded;

  if(sum == 0b1101 || sum == 0b0100 || sum == 0b0010 || sum == 0b1011) encoderValue ++;
  if(sum == 0b1110 || sum == 0b0111 || sum == 0b0001 || sum == 0b1000) encoderValue --;

  lastEncoded = encoded;
}

Impact9:
I had to use Pins 0 and 1 on the Uno for the Easydriver since the RGB Ringcoder/encoder used Pins 2 & 3 according to Bildr guide the encoder has to go to Pins 2 & 3. I don't know if using pins 0/1 is okay or not.

Pin's 0 & 1 are Rx and Tx and are used when uploading a sketch and for serial operations (eg. serialPrint). If you've any other pins available, I suggest using them instead. If that's not possible, disconnect them when uploading a sketch and don't print to the serial monitor.

Makes sense. Can I use the analog pins instead?

Yes, you can use the analogue pins as digital inputs/outputs (pins 14 to 19).