Why does this stop after about 30 seconds?

Hi all!

I am trying to control relays by using the millis() function. After a preset time period a relay will fire. I am using two currently. The program works fine for about 30 seconds, then stops. Any ideas? Here is the code:

int Pins = 13;
int relay1 = 250;
int relay2 = 750;
int relayState1 = LOW;
int relayState2 = LOW;
long previousMillis1 = 0;
long previousMillis2 = 0;
unsigned long currentMillis = 0;

void setup()

{
  for (int i=1; i < Pins; i++)
  
  {
    pinMode (i, OUTPUT);
  } 
    
}

void loop()

{
  //digitalWrite(1, HIGH);
  currentMillis = millis();
  
  if (currentMillis - previousMillis1 > relay1) 
    {
      previousMillis1 = currentMillis;
      Pin1(currentMillis);
      //previousMillis1 = x;
    } 
  if (currentMillis - previousMillis2 > relay2)
    {
      previousMillis2 = currentMillis;
      Pin2(currentMillis);
    }
}

void Pin1(int x)
  {
    previousMillis1 = x;
    if (relayState1 == LOW)
    //{
      relayState1 = HIGH;
    //}
    else
    //{
      relayState1 = LOW;
    //}  
    digitalWrite(1, relayState1);
  }
  
void Pin2(int y)
  {
    previousMillis2 = y;
    if (relayState2 == LOW)
    //{
      relayState2 = HIGH;
    //}  
    else
    //{
      relayState2 = LOW;
    //}  
    digitalWrite(2, relayState2);
  }

Thanks in advance.

Tom

try making these unsigned long like the other time variables

long previousMillis1 = 0;
long previousMillis2 = 0;

same with these
void Pin1(int x)
void Pin2(int y)

You are the man! Works great so far. Thanks! I feel dumb for not catching that myself.

Tom

I see mismatched variables a lot in time related things, seemss like an easy thing to fix tho.

You set previousMillis1 and previousMillis2 in the loop() function and then set them again in Pin1() and Pin2(). If you had set them only in loop(), the program would have worked.

Pete