How to call 1 of two functions and run once.

Hey there, Arduino community.
Obviously looking for some help in my very simply project.

Basically, if pin 2 is High then run function "relayF1" once,
if pin 2 is LOW then run function "relayF2" once.

If pin 2 is HIGH: activate Relay#1 for 2 seconds.
If pin 2 is LOW: activate Relay #2 for 2 seconds.

Right now it runs either of the functions repeatedly--depending on the state of pin 2.

Thanks in advance!!

int GPIstate = 0 ;
int input1 = 2;       // input detection pin set to Digital pin 2
int relay1 = 7;       // output 1 relay on digital Pin 7,6,5, etc
int relay2 = 6;  

void setup() {
 pinMode(input1, INPUT); // initialize input 1 pin as INPUT            
 pinMode(relay1, OUTPUT);  // initialize relay 2  
 pinMode(relay2, OUTPUT); // initialize relay 2

Serial.begin(9600);
}


void loop(){
  GPIstate = digitalRead(input1);

  if (GPIstate == HIGH) {   
    relayF1(); 
    }
    
  else {
    relayF2();
}
}

void relayF1(){
    digitalWrite(relay1, HIGH);  //change Relay 1 Pin to HIGH
    Serial.println("GPI Detected - Relay 1 Engage - Pause 2 Seconds"); //Print result
        delay(2000);  //wait 2 seconds
    digitalWrite(relay1, LOW);  //change Relay 1 Pin to LOW
    Serial.println("Relay 1 Disengage");  //Print result
    delay(500);  //cleanup
}

void relayF2(){
    digitalWrite(relay2, HIGH); //change Relay 2 Pin to HIGH
    Serial.println("GPI Detected - Relay 2 Engage - Pause 2 Seconds"); //Print result
        delay(2000); //wait 2 seconds
    digitalWrite(relay2, LOW); //change Relay 2 Pin to LOW
    Serial.println("Relay 2 Disengage"); //Print result
    delay(500); //cleanup
}

Look at the state change example in the IDE for a clue.

Amazing. Thanks, so much!

A few minutes of analyzing the example was all I needed.

Here is my final working sketch for anyone else who may benefit in the future.

int input1 = 2;       // input detection pin set to Digital pin 2
int relay1 = 7;       // output 1 relay on digital Pin 7,6,5, etc
int relay2 = 6;  

int GPIcounter = 0;   
int GPIstate = 0 ;
int lastGPIstate = 0;     // previous state of the button


void setup() {
 pinMode(input1, INPUT); // initialize input 1 pin as INPUT            
 pinMode(relay1, OUTPUT);  // initialize relay 2  
 pinMode(relay2, OUTPUT); // initialize relay 2

Serial.begin(9600);
}


void loop(){
  GPIstate = digitalRead(input1);

 // compare the buttonState to its previous state
  if (GPIstate != lastGPIstate) {
    // if the GPI state has changed, call function relayF1
    if (GPIstate == HIGH) {
      // if the current state is HIGH then the GPI state went from off to on:
      relayF1();
    } else {
     
      relayF2();
    }
    // Delay a little bit to avoid bouncing
    delay(50);
  }
  // save the current state as the last state, for next time through the loop
lastGPIstate = GPIstate;
 
}

void relayF1(){
    digitalWrite(relay1, HIGH);  //change Relay 1 Pin to HIGH
    Serial.println("GPI Detected - Relay 1 Engage - Pause 2 Seconds"); //Print result
        delay(2000);  //wait 2 seconds
    digitalWrite(relay1, LOW);  //change Relay 1 Pin to LOW
    Serial.println("Relay 1 Disengage");  //Print result
    delay(500);  //cleanup
}

void relayF2(){
    digitalWrite(relay2, HIGH); //change Relay 2 Pin to HIGH
    Serial.println("GPI Detected - Relay 2 Engage - Pause 2 Seconds"); //Print result
        delay(2000); //wait 2 seconds
    digitalWrite(relay2, LOW); //change Relay 2 Pin to LOW
    Serial.println("Relay 2 Disengage"); //Print result
    delay(500); //cleanup
}