maintain a polarity reversal

I am looking for suggestions on how to reverse and maintain a polarity reversal for “in1 & in2” when a monetary button is pressed. This would be inputs 3 and or 12. The remaining code appears to be working.

int enA = 8;
int in1 = 9;
int in2 = 10;
int endoftrackleft12 = 12;
int endoftrackright3 = 3;
int stationeast4 = 4;
int stationsouth5 = 5;
int stationwest6 = 6;
//int val = 0;

//int state = HIGH; // the current state of the output pin
//int reading; // the current reading from the input pin
//int previous = LOW; // the previous reading from the input pin
// the follow variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
//long time = 0; // the last time the output pin was toggled
long debounce = 200; // the debounce time, increase if the output flickers

unsigned long startTime;
unsigned long currentTime;
unsigned long period = 5000; //adjust to change period
boolean timing = false;

byte currentButtonState2 = HIGH;
byte previousButtonState2 = HIGH;
byte currentButtonState3 = HIGH;
byte previousButtonState3 = HIGH;
byte currentButtonState4 = HIGH;
byte previousButtonState4 = HIGH;
byte currentButtonState5 = HIGH;
byte previousButtonState5 = HIGH;
byte currentButtonState6 = HIGH;
byte previousButtonState6 = HIGH;

/*
void setMotor(int speed, boolean reverse)
{
analogWrite(enA, speed);
digitalWrite(in1, ! reverse);
digitalWrite(in2, reverse);
}
*/

void setup()
{

{
// set all the motor control pins to outputs
pinMode(enA, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);

pinMode (endoftrackleft12, INPUT_PULLUP);
pinMode (endoftrackright3, INPUT_PULLUP);
pinMode (stationeast4, INPUT_PULLUP);
pinMode (stationsouth5, INPUT_PULLUP);
pinMode (stationwest6, INPUT_PULLUP);

Serial.begin(9600); // Use serial for debugging
digitalWrite(endoftrackleft12, HIGH);
digitalWrite(endoftrackright3, HIGH);
digitalWrite(stationeast4, HIGH);
digitalWrite(stationsouth5, HIGH);
digitalWrite(stationwest6, HIGH);
}
}

void loop()
{

// H-bridge
// Set speed to 200 out of possible range 0~255
analogWrite(enA, 200);

//===========================
// Station East Control
currentTime = millis();
if (!timing) //only react to input if not already timing
{
previousButtonState4 = currentButtonState4;
currentButtonState4 = digitalRead(stationeast4);
if (currentButtonState4 != previousButtonState4 & currentButtonState4 == LOW) //button has become pressed
{
digitalWrite(in1, HIGH);
digitalWrite (in2, HIGH);
startTime = millis();
timing = true;
}
}
else if (currentTime - startTime >= period)
{
digitalWrite(in1, LOW);
digitalWrite (in2, HIGH);
timing = false;
}
//=================
//Station South Control
currentTime = millis();
if (!timing) //only react to input if not already timing
{
previousButtonState5 = currentButtonState5;
currentButtonState5 = digitalRead (stationsouth5);
if (currentButtonState5 != previousButtonState5 & currentButtonState5 == LOW) //button has become pressed
{
digitalWrite(in1, HIGH);
digitalWrite (in2, HIGH);
startTime = millis();
timing = true;
}
}
else if (currentTime - startTime >= period)
{
digitalWrite(in1, LOW);
digitalWrite (in2, HIGH);
timing = false;
}

//=================
// Station West Control
currentTime = millis();
if (!timing) //only react to input if not already timing
{
previousButtonState6 = currentButtonState6;
currentButtonState6 = digitalRead (stationwest6);
if (currentButtonState6 != previousButtonState6 & currentButtonState6 == LOW) //button has become pressed
{
digitalWrite(in1, HIGH);
digitalWrite (in2, HIGH);
startTime = millis();
timing = true;
}
}
else if (currentTime - startTime >= period)
{
digitalWrite(in1, LOW);
digitalWrite (in2, HIGH);
timing = false;
}

/*
reading = digitalRead(endoftrackleft2);

// if the input just went from LOW and HIGH and we've waited long enough
// to ignore any noise on the circuit, toggle the output pin and remember
// the time
if (reading == HIGH && previous == LOW && millis() - time > debounce) {
if (state == HIGH)
state = LOW;
else
state = HIGH;

time = millis();
}
digitalWrite(in1, state);
digitalWrite(in2, state);
previous = reading;
*/
}

The usual way to remember something is to store it in a variable. It can be a global variable or, as used below, a static local variable; depends on preferencesand where the variable needs to be used what is the preferred way.

E.g.

void loop()
{
  static bool pressed = false;
  if(digitalRead(somePin)==HIGH)
  {
    pressed = true;
  }
}