triggerable counters

Here is your original code as requested.

unsigned long periodStartMillis;
unsigned long currentMillis;
const unsigned long period = 5000; //period during which button input is valid
const byte buttonPin1 = A1; //button on pin A1
byte currentButtonState;
byte previousButtonState;
int count = 0;
boolean printFinalMessage = true;
unsigned long debounceStartMillis;
unsigned long debouncePeriod = 20;
boolean debouncing = false;

void setup()
{
Serial.begin(115200);
pinMode(buttonPin1, INPUT_PULLUP);
Serial.println("Press the button as many times a possible in 5 seconds");
periodStartMillis = millis();
}

void loop()
{
currentMillis = millis();
if (currentMillis - periodStartMillis <= period) //true until the period elapses
{
previousButtonState = currentButtonState; //save the previous button state
currentButtonState = digitalRead(buttonPin1); //read the current state of the input
if (currentButtonState != previousButtonState) //if the button state has changed
{
debounceStartMillis = currentMillis; //save the time that the state change occured
debouncing = true; //flag that debouncing in progress
} //end state change check

if (currentMillis - debounceStartMillis >= debouncePeriod) //if the debounce period has elapsed
{
if (debouncing == true) //debouncing taking place
{
if (currentButtonState == LOW) //if the button is currently pressed
{
debouncing = false; //debouncing is finished
count++; //increment the count
Serial.println(count);
} //end count increment
} //end debouncing in progress check
} //end debounce time elapsed check
} //end timing period check
else //period has ended
{
if (printFinalMessage == true)
{
Serial.println("Time is up");
Serial.print("Button pressed count : ");
Serial.println(count);
printFinalMessage = false; //prevent the final message being displayed again
} //end printing final message
} //end final message check
}

periodStartMillis is initiated once in void setup. I am puzzling over weither the initiation of the count can be done with the program running rather than once in the void setup. My aim is to trigger counting when ever I want and as often as I want with the void loop running. As it is it runs the void setup once and then void loops ,counting, until the period expires. I have tried all sorts of programming gambits but it seems to come down to periodStartMillis being settup before the loop commences otherwise it will be re-initiated every time the void loop is run.