You basically have three states that you describe. You can implement something with a switch statement
void loop()
{
// the start time of the 'action'
static unsigned long timerStarttime = 0;
// the current state
static byte currentState = 1;
switch (currentState)
{
case 1:
if (timerStarttime == 0)
{
// switch pin 7 on
...
// set the start time
timerStarttime = millis();
}
else
{
if (timerStarttime - millis() >= 300000UL)
{
// switch pin 7 off
...
// reset the start time for the next step
timerStarttime = 0;
// 'goto' next step
currentState = 2;
}
}
break;
case 2:
if (timerStarttime == 0)
{
// switch pin 9 on
...
// set the start time
timerStarttime = millis();
}
else
{
if (timerStarttime - millis() >= 720000UL)
{
// switch pin 9 off
...
// reset the start time for the next step
timerStarttime = 0;
// 'goto' next step
currentState = 3;
}
}
break;
case 3:
if (timerStarttime == 0)
{
// switch pin 7 on
...
// set the start time
timerStarttime = millis();
}
else
{
if (timerStarttime - millis() >= 540000UL)
{
// switch pin 7 off
...
// reset the start time for the next step
timerStarttime = 0;
// 'goto' next step
currentState = 1;
}
}
break;
}
}
This is just sample code to show how to approach your problem; it simply does something for 5 minutes, something else for 12 minutes and the something else again for 9 minutes. Because in the last state (step) the currentState is set to one, this will be a forever repeating sequence.
Now there is a lot left to be desired. First is the hard-coded numbers 1, 2 and 3. You can place the following near the top of the code
#define PIN7_5MINUTES 1
#define PIN9_12MINUTES 2
#define PIN7_9MINUTES 3
Replace PINX by something more sensible that reflects what actually happens.
Next is that the first code basically contains 3 repeating blocks doing the same thing, just different pins and different durations. You can place this in a function
/*
do an action (pin on for given duration followed by pin off)
in:
delayTime: time that pin must be on
pinNNumber: the pin to control
returns:
false while action in progress, true when action finished
*/
bool action(unsigned long delayTime, byte pinNumber)
{
// the start time of the 'action'
static unsigned long timerStarttime = 0;
if (timerStarttime == 0)
{
// switch pin on
digitalWrite(pinNumber, HIGH);
// set the start time
timerStarttime = millis();
}
else
{
if (timerStarttime - millis() >= delayTime)
{
// switch pin off
digitalWrite(pinNumber, LOW);
// reset the start time that we use this function
timerStarttime = 0;
// indicate that we're done with this
return true;
}
}
// indicate that the action is in progress
return false;
}
And call that function in the different cases.
void loop()
{
// the current state
static byte currentState = 1;
switch (currentState)
{
case 1:
if (action(300000UL, 7) == true)
{
// 'goto' next step
currentState = PIN9_12MINUTES;
}
break;
case 2:
if (action(720000UL, 9) == true)
{
// 'goto' next step
currentState = PIN7_9MINUTES;
}
break;
case 3:
if (action(540000UL, 7) == true)
{
// 'goto' next step
currentState = PIN7_5MINUTES;
}
break;
}
}
Hope this gives you the idea.