Replacing an encoder with a magnetic sensor ( I have the code)

So my goal is to build program a robot. I have a rotary encoder (or a potentiometer) attached to the wheel and every time the wheel spins, the friction turns the encoder and calculated the distance for me. But for more accurate results, I have since put a magnet on the wheel and taped a sensor so that everytime the magnet passes one revolution, the magnetic sensor can record it.

I also have replaced the potentiometer on the back wheel (controls steering) with a motor that is both a motor and has an encoder on top.

I have a simple code that lights up an LED whenever the magnet comes close. So can anyone guide me what to do next?

 The circuit:
 * potentiometer connected to analog pin 0.
   Center pin of the potentiometer goes to the analog pin.
   side pins of the potentiometer go to +5V and ground
 * "P" channel on motor driver connected to digital pin 9
 * "D" channel on motor driver connected to digital pin 7
 

 
 */

// These constants won't change.  They're used to give names
// to the pins used:
const int analogInPin = A0;  // Analog input pin that the potentiometer is attached to
const int analogOutPin = 9; // Analog output pin that the "P" channel is attached to (PWM Signal)
const int digitalOutPin = 7; // Digital output pin that the "D" channel is attached to (controls motor Direction)
const int pump = 10;

// PID Gains
const int PGain = 3;
const int DGain = 1;
const int IGain = 0.05;

// Input and Output Variables
int sensorValue = 0;        // value read from the pot
int outputValue = 0;        // value output to the PWM (analog out)

// Variables needed for Control Law
double potAngle = 0;			// value in degrees
double prevPotAngle = 0;		// previous value read from pot
double desiredPosition = 185;		// desired position (in degrees) we want the motor to go to
double error = 0;				// current error
double motorVelocity = 0;		// first derivative of motorPosition
double errorIntegral = 0;		// used in PID control law
double controlSignal = 0;		// control signal sent to the motor
double interval = 50;
long previousMillis = 0;



// Time keeping variables
int count = 0;				// keeps track of time (for switching desired position)
int dt = 1;					// time it takes to execute one loop (in ms)
int encoderPin1 = 2;
int encoderPin2 = 3;
int pumpstate = LOW;

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


////////////////////////stuff/to/chage/////////////////////////////////////////////

int steerangle = 217;
int distance = 330;
int brakeangle = 74;

///////////////////////////////////////////////////////////////////////////////


long lastencoderValue = 0;

int lastMSB = 0;
int lastLSB = 0;

unsigned long time;


void setup() {
  // initialize serial communications at 9600 bps:
  Serial.begin(9600); 		// This allows us to write values to the Serial Monitor
  pinMode(digitalOutPin, OUTPUT);	// sets the "D" channel pin to an output
  pinMode(pump, OUTPUT);
  pinMode(encoderPin1, INPUT); 
  pinMode(encoderPin2, INPUT);

  digitalWrite(encoderPin1, HIGH); //turn pullup resistor on
  digitalWrite(encoderPin2, HIGH); //turn pullup resistor on

  //call updateEncoder() when any high/low changed seen
  //on interrupt 0 (pin 2), or interrupt 1 (pin 3) 
  attachInterrupt(0, updateEncoder, CHANGE); 
  attachInterrupt(1, updateEncoder, CHANGE);
  desiredPosition = 90;

}


void loop() {
  // read the analog in value:
  
  sensorValue = analogRead(analogInPin);  // Read as an integer b/w 0 and 1023 (10-bit resolution)
  
  // First save the previous value
  prevPotAngle = potAngle;
  // then save the new value, mapping it to a value in degrees:
  potAngle = map(sensorValue, 0, 1023, 0, 360); 
  
  // use it to compute error and motor speed
  error = potAngle - desiredPosition;
  motorVelocity = (potAngle - prevPotAngle)/(dt); // (in deg/ms)
  errorIntegral = errorIntegral + error*(dt/1000); 
  
  // Calculate the motor control signal using a PID control law
  controlSignal = -1*PGain*error - DGain*motorVelocity - IGain*errorIntegral;	
  
  unsigned long currentMillis = millis();
  
  
   // tell the motor which way to spin
  if (controlSignal >= 0) {
	digitalWrite(digitalOutPin, HIGH);
  } else {
	digitalWrite(digitalOutPin, LOW);
  }
    
  // map it to the range of the analog out:
  controlSignal = abs(controlSignal);  // can only ouptut positive values
  outputValue = constrain(controlSignal, 0, 255);  // 8-bit resolution
  
  // change the analog out value:
  analogWrite(analogOutPin, outputValue);         

   if(currentMillis - previousMillis > interval) {
    // save the last time you blinked the LED 
    previousMillis = currentMillis;   

    // if the LED is off turn it on and vice-versa:
    if (pumpstate == LOW)
      pumpstate = HIGH;
    else
      pumpstate = LOW;

    // set the LED with the ledState of the variable:
    digitalWrite(pump, pumpstate);
  }

if (encoderValue>=distance)
{
  pumpstate=LOW;
}

if (currentMillis>=57000)
{
  pumpstate=HIGH;
}


  // print the results to the serial monitor: (UNCOMMENT TO DISPLAY)
//  Serial.print("Desired Position = " );                       
//  Serial.print(desiredPosition);      
//  Serial.print("\t Actual Position = ");      
//  Serial.print(potAngle);
//  Serial.print("\t Rotarty = ");
//  Serial.println(encoderValue);  


  
  
  if (encoderValue >=distance) {
    desiredPosition = brakeangle;}
    else {
      desiredPosition = steerangle;
    }
    
}



void updateEncoder(){
  int MSB = digitalRead(encoderPin1); //MSB = most significant bit
  int LSB = digitalRead(encoderPin2); //LSB = least significant bit

  int encoded = (MSB << 1) |LSB; //converting the 2 pin value to single number
  int sum  = (lastEncoded << 2) | encoded; //adding it to the previous encoded value

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

  lastEncoded = encoded; //store this value for next time
}

you want to control movement. ? ..and replace N pulses/rev with one pulse/rev ?? this is diffucult to understand! ....................... To get 'full control' - do like LEGO .. use stepper motors