Optical encoder too output moter adafruit motor sheld help

ok after a lot of playing i have got the basic concept to actually work using the Adifuit Motor shield
If anyone interested this is the basic code

// Madmax/Mydakota Motor Shield Mod to Follow encoder


#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_MS_PWMServoDriver.h"

    int state, prevstate = 500, count = 500;
    int nextEncoderState[4] = { 2, 0, 3, 1 };
    int prevEncoderState[4] = { 1, 3, 0, 2 };



    // Number of steps per turn of encoder
    int forward=1;
    int backward=1;

    //Used to calculate direction
    int direct=0;

Adafruit_MotorShield AFMS = Adafruit_MotorShield(); 
    // Connect a stepper motor 
    // to motor port #1 #2 (M3 and M4)
    Adafruit_StepperMotor *myMotor = AFMS.getStepper(48, 1);

    void setup() {
     AFMS.begin();
    myMotor->setSpeed(10);
  

      pinMode(10, INPUT);
      pinMode(2, INPUT);
      pinMode(9, OUTPUT);
      digitalWrite(9, LOW);
      digitalWrite(2, HIGH);
      digitalWrite(10, HIGH);
      Serial.begin(115200);

    }

    void loop() {
       
       state = (digitalRead(10) << 1) | digitalRead(2);
      if (state != prevstate) {
        if (state == nextEncoderState[prevstate]) {
           count++;
           direct= count-1;
           
          if (count > direct){
         
          myMotor->step(FORWARD, SINGLE);
           
           
       Serial.println("________forward____________________");// used for testing purpose
       direct=0; 

     
       }
           
         
        } else if (state == prevEncoderState[prevstate]) {
           count--;
           direct= count+1;
           
            if (count < direct){
       
           myMotor->step(100, BACKWARD, SINGLE);
           
         
         
           Serial.println("__________backward_________________");// used for testing purpose
          direct=0;
         
        }
        }
        Serial.print("count =");
        Serial.println(count, DEC);
        Serial.println(direct, DEC);
        Serial.print("prev count =");
       
     
        prevstate = state;
     
        }


    }