Looking for assistance with summing encoder counts

Hello, I have been going in circles ( no pun intended) for two days with this and I am not getting anywhere.
I have a simple DC motor and encoder from here: Pololu - 131:1 Metal Gearmotor 37Dx57L mm 12V with 64 CPR Encoder (No End Cap)
I am using 3 pushbuttons to send the motor to 3 different positions – which are + 1 rev, + 2 rev and then reverse one rev.
I am counting encoder pulses in the serial monitor and I am trying to sum the all of the encoder moves to see how far off I am from my desired tick count. The motor overshoots the desired tick count, which is fine for now. My plan is to then to try and implement PID control to see if I can hit my encoder counts to the same number as the desired tick number.
My problem now is I can’t get the math right for summing encoder counts after each push button. I have a two second pause in the print command to let the motor reach its position before I print the counts to the monitor. As I understanding it the counts stay in memory until a new “move” command is run and then the count zeros and starts counting again until the motor stops.
So I push button 1, get a count, but then I am trying to zero the counter, push button 1 (or 2 or 3) then add the new count to the old count and get a total count. Simply put, I want to push any combination of forward and reverse buttons (pausing in-between to let the motor reach its destination) for 20 repetitions and be able to see how many counts I am off from my desired tick count.
I have tried zeroing the count in between button pushes, using the button to trigger a math function to add to the count (doesn’t work as it takes 1-2 seconds for the motor to reach its final count), looking at a change in counts using a compare function (works when the count is different but not when the same button is pushed over and over), and a couple of other methods.
I always get a constant summing of counts even when there are no button pushes, or I can’t get the count to increment at all.
Here is my non-working code, for now I have commented out push buttons 2 and 3.

I feel I am going about this incorrectly and I should take an entirely new approach - any guidance or suggestions are welcome, thank you

// MD03A_Motor_basic + encoder
//credit to: KAS http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1282384853
// credit to JohnWasser
// 
const int InA1       = 10;      // Pin 10, goes to Pololu INA motor direction pin (low forward, high reverse)
const int InB1       = 11;      // Pin 11, goes to Pololu INB motor direction pin (low reverse, high forward)
const int PWM1    =    6;       // Pin 6, goes to Pololu PWM pin (speed)
const int encodPinA1 =  3;       // Pin 3, reads encoder A signal (yellow)
//const int encodPinB1  = 8;       // Pin 8, reads encoder B signal (White)
const int FORWARD   =  1;       // 
const int BACKWARD  =  2;      // 
const int buttonPin =  A0;      // Analog pin A0, reads Voltage of button 1, 2, or 3
unsigned long lastMilli = 0;       // loop timing
unsigned long lastMilliPrint = 0;  // loop timing
volatile long count = 0;              // motion counter
volatile long ticks = 0;              // motion end point
volatile boolean run = false;         // motor moves
int buttonValue = 0;       // defines switchValue as an interger, sets value at 0 (of 0 -1023)

long previousMillis = 0;        // will store last time print was updated
long interval = 200;           // interval at which to print

int lastCount = 0;
int totalCount = 0;
int lastMove = 0;
int oldCount = 0;

//

void setup() {
  pinMode(InA1, OUTPUT);           // direction to Pololu motor board
  pinMode(InB1, OUTPUT);           // direction to Pololu motor board
  pinMode(PWM1, OUTPUT);           // PWM output to Pololu motor board
  pinMode(encodPinA1, INPUT);      // input from encoder
  //pinMode(encodPinB1, INPUT);      // input from encoder
  pinMode(buttonPin,INPUT);           // pin A0, reads V input from buttons
  digitalWrite(encodPinA1, HIGH);      // turn on pullup resistor pin 10
  //digitalWrite(encodPinB1, HIGH);      // turn on pullup resistor pin 11
  attachInterrupt(1, rencoder, FALLING); 
  Serial.begin(9600);                 // set up Serial library at 9600 bps
  
}

void loop() 
          {
  buttonValue = analogRead(buttonPin);   // Read Voltage on pin A0
  {
  if(buttonValue>940)                   // Button #1 470 resistor 992 max (1023=5v)
    {
      moveMotor(FORWARD, 250, 2000*1);      // direction, PWM (speed), ticks number (2000=360°)
      addCount;                          // calls math function to add current count
    }
  }
    
  //buttonValue = analogRead(buttonPin);  
    //if(buttonValue>750 && buttonValue<800)  // Button #2 4.7k resistor  790 max, min = less than bttn #1
    //moveMotor(FORWARD, 250, 2000*2);        // direction, PWM (speed), ticks number (2000=360°)    
  
  //buttonValue = analogRead(buttonPin);  
  //if(buttonValue>600 && buttonValue<630)  // Button #3 10k resistor  620 max, min = less than bttn #2
    //moveMotor(BACKWARD, 250, 2000*1);       // direction, PWM (speed), ticks number (2000=360°)
    
     printCount(2000);   // prints count every  2 seconds 
 }
 
void moveMotor(int direction, int PWM_val, long tick)  {
  count = 0;                                // abs(count)
  ticks = tick;
  if(direction==FORWARD)    
    motorForward(PWM_val);
  else 
    if(direction==BACKWARD)    
    motorBackward(PWM_val);
}
void rencoder() {                           // pulse and direction, direct port reading to save cycles
  count++;
  if(run && count >= ticks)      
    motorBrake();
}

void motorForward(int PWM_val)  {
  analogWrite(PWM1, PWM_val);
  digitalWrite(InA1, LOW);
  digitalWrite(InB1, HIGH);
  run = true;
}

void motorBackward(int PWM_val)  {
  analogWrite(PWM1, PWM_val);
  digitalWrite(InA1, HIGH);
  digitalWrite(InB1, LOW);
  run = true;
}

void motorBrake()  {
  analogWrite(PWM1, 0);
  digitalWrite(InA1, HIGH);
  digitalWrite(InB1, HIGH);
  run = false;
}

void addCount()
  {
    lastMove = count;
  }

void printCount(long interval) // function "blink", "interval" is a "long" parameter assigned to the "blink" function
                          // 1000 is passed into "interval" when "blink(1000)" is run
    {
     if (millis() - previousMillis > interval) // if (current time - below marked time > 1000) is true, then run below
        {
          previousMillis = millis();  // mark the time when the above is true (current time - previous time > 1000)
          totalCount = (lastMove + oldCount);
          oldCount = count;
          Serial.print("total  "  );
          Serial.println(totalCount);
         }
    }

Hard to see what is going wrong without getting some debug output from 'real time' as it is running. I implemented a similar bit of code to test a motor controller I put together. I have attached it here so you can see an alternative way of doing this, using a state machine.

I had 4 control buttons - FWD, REV, STOP, EMERGENCY STOP - and an interrupt driven counter which was counting the transition between segments of a black/white segmented wheel. I was testing reamping the motor up to speed and then back down again, leading to a PID implementation later. Hope this helps.

#define  STATE_DEBUG  1
#define  SPEED_DEBUG  0

#define  IN1  5 // input1 on L298
#define  IN2  6 // input2 on L298
#define  ENA  7 // enable A on L298

#define  BUT_FWD  11  // forward
#define  BUT_REV  10  // reverse
#define  BUT_STOP  9  // stop
#define  BUT_ESTOP 8  // e-stop

// RPM counter and ISR
#define  PULSE    2            // pulse input from feeback device
#define  PULSE_PER_REV  10     // pulses counted per revolution - this depends on the feeback device
#define  RPM_CALC_INTERVAL  500  // milliseconds  
volatile long pulseCount = 0;  // pulse counter
unsigned int  motorRPM;        // calculated RPM

// Defines for command buttons
#define  CMD_ESTOP 0
#define  CMD_STOP  1
#define  CMD_FWD   2
#define  CMD_REV   3

volatile uint8_t Command = CMD_ESTOP;

// Motor constants
#define  MIN_POWER  70      // PWM setting for minimum movement of motor
#define  MAX_POWER  255     // PWM setting for maximum power to motor

// The current stater of the motor
#define  MOTOR_BRAKE         0
#define  MOTOR_STOP          1
#define  MOTOR_RUN           2
#define  MOTOR_PRE_RAMP_UP   3
#define  MOTOR_RAMP_UP       4
#define  MOTOR_PRE_RAMP_DOWN 5
#define  MOTOR_RAMP_DOWN     6

#define  DIR_UNDEF  0
#define  DIR_FWD    1
#define  DIR_REV    2

#define  RAMP_UP_TIME    1000  // ms
#define  RAMP_DOWN_TIME  1000  // ms

uint8_t  motorState = MOTOR_BRAKE;     // current state for the motor
uint8_t  motorDirection = DIR_UNDEF;   // current direction for the motor
uint16_t motorSpeedSP = MAX_POWER;     // motor speed setpoint (MIN_POWER, MAX_POWER)
uint8_t  motorSpeedCV;                 // motor speed current value
unsigned long  timerRamp = 0;          // timer to keep track of ramping time elapsed

#if  STATE_DEBUG
#define  StateTransition(S, N)  { Serial.print(State2Str(S)); Serial.print(" -> "); S = (N); Serial.println(State2Str(S)); }
#else
#define  StateTransition(S, N)  S = (N);
#endif

const char* State2Str(uint8_t S)
{
  switch (S)
  {
    case MOTOR_BRAKE:          return("MOTOR_BRAKE");
    case MOTOR_STOP:           return("MOTOR_STOP");
    case MOTOR_RUN:            return("MOTOR_RUN");
    case MOTOR_PRE_RAMP_UP:    return("MOTOR_PRE_RAMP_UP");
    case MOTOR_RAMP_UP:        return("MOTOR_RAMP_UP");
    case MOTOR_PRE_RAMP_DOWN:  return("MOTOR_PRE_RAMP_DOWN");
    case MOTOR_RAMP_DOWN:      return("MOTOR_RAMP_DOWN");
  }
  return("???");
}

void setup ()
{
  pinMode(IN1,OUTPUT);
  pinMode(IN2,OUTPUT);
  pinMode(ENA,OUTPUT);

  pinMode(BUT_REV, INPUT);     
  pinMode(BUT_FWD, INPUT);     
  pinMode(BUT_STOP, INPUT);     
  pinMode(BUT_ESTOP, INPUT);     

  pinMode(PULSE, INPUT);

#if (STATE_DEBUG || SPEED_DEBUG)
  Serial.begin(57600);
  Serial.println("[L298 Motor Control Tester]");
#endif

  // finally connect thre interrupt
  attachInterrupt((PULSE == 2) ? 0 : 1, irqPulseCounter, RISING);
}

uint8_t ReadCommand(uint8_t cmdDefault)
{
  // check change of state
  if      (digitalRead(BUT_ESTOP)) return(CMD_ESTOP);
  else if (digitalRead(BUT_STOP))  return(CMD_STOP);
  else if (digitalRead(BUT_FWD))   return(CMD_FWD);
  else if (digitalRead(BUT_REV))   return(CMD_REV);

  return(cmdDefault);
}

// IRQ and RPM routines
void irqPulseCounter()
{
  pulseCount++;
}

void CalculateRPM()
{
  static uint8_t  lastState = MOTOR_STOP;
  static unsigned long timerZero;       // baseline of millis() function for current calculations
  
  if (motorState == MOTOR_RUN)    // is currently running
  {
    if (lastState == MOTOR_RUN)   // and was running on the last call
    {
      if (millis()-timerZero < RPM_CALC_INTERVAL) return;  // only calculate every CALC_INTERVAL ms  
      motorRPM = 1000 * (pulseCount / PULSE_PER_REV) / (millis() - timerZero);
    }

    // either has just started running or we need to reset for the calculation
    pulseCount = 0;
    timerZero = millis();    
  }
  else                            // is not currently running
  {
    if (lastState == MOTOR_RUN)   // and was running on the last call
      motorRPM = 0;
  }    
  
  lastState = motorState;
}

void SetSpeed(uint8_t direction, uint8_t speed)
{
    if (direction == DIR_FWD)
    {
      digitalWrite(IN1, LOW);
      analogWrite(IN2, speed);
      digitalWrite(ENA, HIGH);
    } 
    else 
    {
      analogWrite(IN1, speed);
      digitalWrite(IN2, LOW);
      digitalWrite(ENA, HIGH);
    }
}

void loop()
{
#if  SPEED_DEBUG
  Serial.print("R ");
  Serial.print(motorRPM);
  Serial.print(": S ");
  if (motorDirection != DIR_UNDEF)
    Serial.print(motorDirection == DIR_FWD ? "+" : "-");
  Serial.print(motorSpeedCV);
  Serial.print("\n");
#endif

  Command = ReadCommand(Command);
  
  if ((Command == CMD_ESTOP) && (motorState != MOTOR_STOP))
  {
    StateTransition(motorState, MOTOR_BRAKE);
  }
  
  switch(motorState)
  {
  case MOTOR_BRAKE:
    digitalWrite(IN1,HIGH);
    digitalWrite(IN2,HIGH);
    digitalWrite(ENA,HIGH);
    motorDirection = DIR_UNDEF;
    motorSpeedCV = 0;
    StateTransition(motorState, MOTOR_STOP);
    break;
    
  case MOTOR_STOP:
    if ((Command == CMD_FWD) || (Command == CMD_REV))
    {
      motorDirection = (Command == CMD_FWD) ? DIR_FWD : DIR_REV;
      StateTransition(motorState, MOTOR_PRE_RAMP_UP);
    }
    break;
    
  case MOTOR_PRE_RAMP_UP:
    motorSpeedCV = MIN_POWER;
    timerRamp = millis();
    StateTransition(motorState, MOTOR_RAMP_UP);
    break;
    
  case MOTOR_RAMP_UP:
    if (millis()-timerRamp < RAMP_UP_TIME)
    {
      motorSpeedCV = MIN_POWER + (((motorSpeedSP-MIN_POWER) * (millis()-timerRamp)) / RAMP_UP_TIME);
    } 
    else 
    {
      motorSpeedCV = motorSpeedSP;
      StateTransition(motorState, MOTOR_RUN);
    }
    SetSpeed(motorDirection, motorSpeedCV);
    break;
    
  case MOTOR_RUN:
    if (Command == CMD_STOP) 
    {
      StateTransition(motorState, MOTOR_PRE_RAMP_DOWN);
    }
    break;

  case MOTOR_PRE_RAMP_DOWN:
    timerRamp = millis();
    StateTransition(motorState, MOTOR_RAMP_DOWN);
    break;
    
  case MOTOR_RAMP_DOWN:
    if (millis()-timerRamp < RAMP_DOWN_TIME)
    {
      motorSpeedCV = motorSpeedSP - (((motorSpeedSP-MIN_POWER) * (millis()-timerRamp)) / RAMP_DOWN_TIME);
    } 
    else 
    {
      StateTransition(motorState, MOTOR_BRAKE);
    }
    SetSpeed(motorDirection, motorSpeedCV);
    break; 
  } 

  CalculateRPM();
}

This version will display the total count about 1/2 second after the move ends.

// MD03A_Motor_basic + encoder
//credit to: KAS http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1282384853
// credit to JohnWasser
const int InA1       = 10;      // Pin 10, goes to Pololu INA motor direction pin (low forward, high reverse)
const int InB1       = 11;      // Pin 11, goes to Pololu INB motor direction pin (low reverse, high forward)
const int PWM1    =    6;       // Pin 6, goes to Pololu PWM pin (speed)
const int encodPinA1 =  3;       // Pin 3, reads encoder A signal (yellow)
//const int encodPinB1  = 8;       // Pin 8, reads encoder B signal (White)

const int FORWARD   =  1;       // 
const int BACKWARD  =  2;      // 

const int buttonPin =  A0;      // Analog pin A0, reads Voltage of button 1, 2, or 3
unsigned long lastMilli = 0;       // loop timing
unsigned long lastMilliPrint = 0;  // loop timing
volatile long count = 0;              // motion counter
volatile long ticks = 0;              // motion end point
volatile boolean run = false;         // motor moves
int buttonValue = 0;       // defines switchValue as an interger, sets value at 0 (of 0 -1023)

long previousMillis = 0;        // will store last time print was updated
long interval = 200;           // interval at which to print

unsigned long totalCount = 0;

void setup() {
  pinMode(InA1, OUTPUT);           // direction to Pololu motor board
  pinMode(InB1, OUTPUT);           // direction to Pololu motor board
  pinMode(PWM1, OUTPUT);           // PWM output to Pololu motor board
  pinMode(encodPinA1, INPUT);      // input from encoder
  //pinMode(encodPinB1, INPUT);      // input from encoder
  pinMode(buttonPin,INPUT);           // pin A0, reads V input from buttons
  digitalWrite(encodPinA1, HIGH);      // turn on pullup resistor pin 10
  //digitalWrite(encodPinB1, HIGH);      // turn on pullup resistor pin 11
  attachInterrupt(1, rencoder, FALLING); 
  Serial.begin(9600);                 // set up Serial library at 9600 bps

}

void loop() 
{
  buttonValue = analogRead(buttonPin);   // Read Voltage on pin A0
  {
    if(buttonValue>940)                   // Button #1 470 resistor 992 max (1023=5v)
    {
      moveMotor(FORWARD, 250, 2000*1);      // direction, PWM (speed), ticks number (2000=360°)
      while(run) ; // Do nothing until the motor move ends
      delay(500);  // Give the motor time to slow down and stop
      totalCount += count;
      Serial.print("total  "  );
      Serial.println(totalCount);
    }
  }
}

void moveMotor(int direction, int PWM_val, long tick)  {
  count = 0;                                // abs(count)
  ticks = tick;
  if(direction==FORWARD)    
    motorForward(PWM_val);
  else 
    if(direction==BACKWARD)    
    motorBackward(PWM_val);
}

void rencoder() {                           // pulse and direction, direct port reading to save cycles
  count++;
  if(run && count >= ticks)      
    motorBrake();
}

void motorForward(int PWM_val)  {
  analogWrite(PWM1, PWM_val);
  digitalWrite(InA1, LOW);
  digitalWrite(InB1, HIGH);
  run = true;
}

void motorBackward(int PWM_val)  {
  analogWrite(PWM1, PWM_val);
  digitalWrite(InA1, HIGH);
  digitalWrite(InB1, LOW);
  run = true;
}

void motorBrake()  {
  analogWrite(PWM1, 0);
  digitalWrite(InA1, HIGH);
  digitalWrite(InB1, HIGH);
  run = false;
}

wonderful, I knew there was a cleaner way to do it!
thanks again for the help