Button+potentiometr delay otside loop

Hello, i'm a newbee, plese help with code & sorry for my bad english :frowning:

i have
-relay shield
-button
-potentiometer 1k or 10k

i need
-if buttonPin is high turn on relay 1,2,3
-then if buttonPin still high & pin9 becomes high turn off relay 2 only
-if button release turn off relay 1,(relay2 is already off), delay for 1-5 seconds (potentiometer sets the time) then turn off relay 3

button pushed continuously until released

i made a code but delay interrupt whole loop

const int buttonPin = 8; //pushbutton pin
const int currentPin = 9; //current sense pin
const int relay1 = 7; //pwm shutdown relay
const int relay2 = 6; //HV ignition relay
const int relay3 = 5; //argon valve relay
const int relay4 = 4; //not used
const int potPin = A2; //potPin

int buttonState = 0;
int currentState = 0;
int gasVal = 0;

void setup() {
pinMode(buttonPin, INPUT);
pinMode(currentPin, INPUT);
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
pinMode(relay3, OUTPUT);
}

void loop() {
buttonState = digitalRead(buttonPin);
currentState = digitalRead(currentPin);
gasVal = analogRead(potPin) * 5;

if (buttonState == HIGH) {
digitalWrite(relay1, HIGH);
digitalWrite(relay3, HIGH);
} else {
digitalWrite(relay1, LOW);
delay(gasVal);
digitalWrite(relay3, LOW);
}

if (buttonState == HIGH && currentState == LOW) {
digitalWrite(relay2, HIGH);
} else {
digitalWrite(relay2, LOW);
}

}

delay interrupt whole loop

No surprise there. delay() stops the program for the specified period

You need to make your timing non blocking by using millis(). See Using millis() for timing. A beginners guide, Several things at the same time and look at the BlinkWithoutDelay example in the IDE.

solved!

Please post your revised code so that others may benefit from it