Shots counter for injector flow bench

At work one of our Diesel injector test benches stopped working. I determined it was the Shots Counter Card. The bench has several cards performing different tasks all made from discrete logic (1985 build date). The shots counter card, as it sounds, counts the number of times an injector is triggered. This is selected at the control panel of the flow bench by a multi position switch. the card reads an IR signal from the Output shaft encoder wheel, and controls three, 12V/120V relays. I'll include the Schematic, what the old card looked like, the replacement Arduino, and an installed and working picture.

#define OPTICAL 2
#define RELAY1 A1
#define RELAY2 A2
#define RELAY3 A3
#define BUTTON 0
#define ZEROCOUNT 1
#define FTYCOUNT 10
#define HNDCOUNT 3
#define HNDFTYCOUNT 4
#define TWOHNDCOUNT 5
#define TWOFTYCOUNT 6
#define THRHNDCOUNT 7
#define FVEHNDCOUNT 8
#define THOUCOUNT 9
long int count;
int buttonState = 1; // variable for reading the pushbutton status
int opticalState = 1;
int countready =0;
volatile long ShotCounter; // counter for the number of shots
long int target;
//int buttonState; // the current reading from the input pin
int lastButtonState = 0; // the previous reading from the input pin
long lastDebounceTime = 0; // the last time the output pin was toggled
long debounceDelay = 30; // the debounce time; increase if the output flickers
int lastOpticalState = 0; // the previous reading from the input pin
long lastOptDebounceTime = 0; // the last time the output pin was toggled
long OptdebounceDelay = 30; // the debounce time; increase if the output flickers

void setup()
{

pinMode(OPTICAL, INPUT);
pinMode(RELAY1, OUTPUT);
pinMode(RELAY2, OUTPUT);
pinMode(RELAY3, OUTPUT);
pinMode(BUTTON, INPUT_PULLUP);
pinMode(ZEROCOUNT, INPUT_PULLUP);
pinMode(FTYCOUNT, INPUT_PULLUP);
pinMode(HNDCOUNT, INPUT_PULLUP);
pinMode(HNDFTYCOUNT, INPUT_PULLUP);
pinMode(TWOHNDCOUNT, INPUT_PULLUP);
pinMode(TWOFTYCOUNT, INPUT_PULLUP);
pinMode(THRHNDCOUNT, INPUT_PULLUP);
pinMode(FVEHNDCOUNT, INPUT_PULLUP);
pinMode(THOUCOUNT, INPUT_PULLUP);

attachInterrupt(0, increment, FALLING);
}

void loop() {
buttonState = 1;
opticalState = 1;

int reading = digitalRead(BUTTON);//<--------------------------------------------------------------------------
if (reading != lastButtonState) {
// reset the debouncing timer
lastDebounceTime = millis(); //debounce
}
if ((millis() - lastDebounceTime) > debounceDelay) {
buttonState = reading;
}
lastButtonState = reading;//<------------------------------------------------------------------------------------

ShotCounter = 0;

if (buttonState == HIGH) {

BY_PASS();
}
else {
DRAIN();
}

}

void BY_PASS()
{
digitalWrite(RELAY1, LOW); //METER SOLENIOD
digitalWrite(RELAY2, HIGH); //BY_PASS SOLENOID
digitalWrite(RELAY3, LOW); //DRAIN SOLENOID

}

void DRAIN()
{
do
{

digitalWrite(RELAY1, LOW); //METER SOLENOID
digitalWrite(RELAY2, HIGH); //BY_PASS SOLENOID
digitalWrite(RELAY3, HIGH); //DRAIN SOLENOID
//------------------------------------------------------------------------------------------------------
if (digitalRead(ZEROCOUNT) == LOW){target = 0;}
if (digitalRead(FTYCOUNT) == LOW){target = 50;} //read position switch
if (digitalRead(HNDCOUNT) == LOW){target = 100;}
if (digitalRead(HNDFTYCOUNT) == LOW){target = 150;}
if (digitalRead(TWOHNDCOUNT) == LOW){target = 200;}
if (digitalRead(TWOFTYCOUNT) == LOW){target = 250;}
if (digitalRead(THRHNDCOUNT) == LOW){target = 300;}
if (digitalRead(FVEHNDCOUNT) == LOW){target = 500;}
if (digitalRead(THOUCOUNT) == LOW){target = 1000;}

//------------------------------------------------------------------------------------------------------
int reading = digitalRead(BUTTON);//<--------------------------------------------------------------------
if (reading != lastButtonState) {
// reset the debouncing timer
lastDebounceTime = millis(); //debounce
}
if ((millis() - lastDebounceTime) > debounceDelay) {
buttonState = reading;
}
lastButtonState = reading;//<---------------------------------------------------------------------------
}
while (buttonState == LOW);

do
{

digitalWrite(RELAY1, LOW); //METER SOLENIOD <-------------- change this to low, only high for debugging
digitalWrite(RELAY2, HIGH); //BY_PASS SOLENOID
digitalWrite(RELAY3, LOW); //DRAIN SOLENOID
// delay(1000);

int reading = digitalRead(BUTTON);//<-----------------------------------------------------------------
if (reading != lastButtonState) {
// reset the debouncing timer
lastDebounceTime = millis(); //debounce
}
if ((millis() - lastDebounceTime) > debounceDelay) {
buttonState = reading;
}
lastButtonState = reading;//<---------------------------------------------------------------------------
}
while (digitalRead(OPTICAL) == HIGH && digitalRead(buttonState) == HIGH);

if (digitalRead (OPTICAL) == LOW)
{

digitalWrite(RELAY1, HIGH); //METER SOLENOID
digitalWrite(RELAY2, LOW); //BY_PASS SOLENOID
digitalWrite(RELAY3, LOW); //DRAIN SOLENOID
ShotCounter = 0;

}

while (ShotCounter < target && digitalRead(BUTTON) == HIGH) {

}
}

void increment()
{
ShotCounter ++;
}