I'll try to explain this for you:
if(switch_state && switch_timestamp && (millis() - switch_timestamp) >= switchPin1TriggeredTime)
Is functionally identical to this:
if (switch_state == HIGH) //The switch is depressed
{
if (switch_timestamp > 0) //The switch was depressed the last time we checked it too
{
if (millis() - switch_timestamp >= switchPin1TriggeredTime) //It's been 2 minutes.
{
//Play a short tone.
}
}
}
To call a function every 2 minutes, you are correct - you would need a variable to track the last time it was called, and update the variable every time you called it. Same exact logic we're using to determine when to press it the first time.
One "hack" you could do to get this working fast, is every time you play the tone, reset the switchPin1TriggeredTime back to the current system clock.
Like so:
if(switch_state && switch_timestamp && (millis() - switch_timestamp) >= switchPin1TriggeredTime) {
//play a short alert tone every minute
playWarningTone();
switch_timestamp = millis() + ( 6000 ); //Re-fire the event every minute after the first 2 minute warning.
}