How to write code for shaft encoder RPM counter?

Here's a simple tach sketch you may be able to adapt for your project, only needs one interrupt pin (pin2) on Uno for encoder channel A, connect encoder channel B to pin 4, its set for 25 PPM & update rate of 2 per second.

unsigned long start;
const byte encoderPinA = 2;//A pin -> interrupt pin 0
const byte encoderPinB = 4;//B pin -> digital pin 4
volatile long pulse;
volatile bool pinB, pinA, dir;
const byte ppr = 25, upDatesPerSec = 2;
const int fin = 1000 / upDatesPerSec;
const float konstant = 60.0 * upDatesPerSec / (ppr * 2);
int rpm;


void setup() {
  Serial.begin(9600);
  attachInterrupt(0, readEncoder, CHANGE);
  pinMode(encoderPinA,INPUT);
  pinMode(encoderPinB,INPUT); 
}

void loop() {
  if(millis() - start > fin)
  {
    start = millis();
    rpm = pulse * konstant;
    Serial.println(rpm);
    pulse = 0;
  }
}

void readEncoder()
{
  pinA = bitRead(PIND,encoderPinA);
  pinB = bitRead(PIND,encoderPinB);
  dir = pinA ^ pinB;          // if pinA & pinB are the same
  dir ? --pulse : ++pulse;    // dir is CW, else CCW
}