Why does this delay hang with certain values?

Hello all, pretty much of a newb here, but trying to work things out. I have an issue with delay hanging when I try to use some values. Yes, I know there are other ways to blink an LED and to time it, such as millis, but I want to understand why this does not work.

The idea is to make the LED flash twice in a 60 second cycle. Flash 1 and Flash 3 happen 60 seconds apart, Flash 2 happens a variable time between 1 and 3. Flash 2 starts close to 1 and then walks closer to 3 for 60 cycles.

Yes, this is part of a larger effort, but this portion of the code will not run on its own for some reason with certain delays selected. For example, if I use 60 in the FOR loop (to get 60 seconds Flash 1 to Flash 3) it will give me the first 2 flashes and then hang, never flashing again after that. But it I use 30 (for a 30 second cycle) it runs fine.

Is there a maximum delay using the DELAY function, and if so have I exceeded it here? Or have I made some other bone headed mistake?

/*
Flash Cycle Investigation
*/


int led = 13;
int FlashSpeed = 4;
int PulseDelay = 0;


void setup()
{
  pinMode(led, OUTPUT);
}


void loop()
{
  FlashCycle();
}


void FlashCycle()
{
  FlashSpeed = 5;
  for (int i=1; i<60; i++)
  {
    Flash();
    delay (1000*i);
    Flash();
    PulseDelay = 60 - i;
    delay (1000*PulseDelay);
  }
}


void Flash()
{
  digitalWrite(led,HIGH);
  delay(25*FlashSpeed);
  digitalWrite(led,LOW);
  delay(25*FlashSpeed);
}

Any ideas? Thanks

T!

(edit) Sorry, did not specify, I am trying to run this on an UNO.

That cannot be the code that you are actually running as it does not compile.

digitaWrite in 2 places instead of digitalWrite and a semi-colon on the end of the for loop statement

Yes, sorry, typos. The computer with the code on it is not connected to the web, and this computer is locked down and cannot have the Arduino environment installed. I manually transcribed from one machine to the other and typoed.

I have corrected the two digtalWrites and the errant semi-colon. The rest appears to match what compiles.

T!

Your problem is with signed sixteen bit arithmetic in the call to your delay().

Edit: it isn't hanging, you're just not being patient enough.

You had a semicolon after the for loop.

This caused your loop to finish and then stop

AWOL:
Your problem is with signed sixteen bit arithmetic in the call to your delay().

Edit: it isn't hanging, you're just not being patient enough.

OK, I think I have it then, if I use more than 32 in my example, say 33, then the delay count becomes 33000, and 2's complement only up to 32767 can be accommodated?

T!

FirstToken:
, and 2's complement only up to 32767 can be accommodated?

Right. ALWAYS use unsigned long variables for millis(), mocros(), delay(), etc.

Excellent, thanks much for the answers.

T!