I Need my arduino to wait for few time , say ( 60s ) initally and should remain idle without carrying out any task and later should execute the loop for every 5 seconds .
is there any way to do that ?
I Need my arduino to wait for few time , say ( 60s ) initally and should remain idle without carrying out any task and later should execute the loop for every 5 seconds .
is there any way to do that ?
Quite a few ways.
No need for "tricks"
how
Sixty seconds delay at the end of setup, and a five second delay at the end of loop.
It's not ideal, but it may get you thinking.
If you don't care about power consumption (that is, you don't need sleep/power down), use a state machine:
unsigned long
timeSketchStart;
const byte pinLed = LED_BUILTIN;
void setup( void )
{
Serial.begin(9600);
pinMode( pinLed, OUTPUT );
Serial.println( F("Sketch starting...") );
timeSketchStart = millis();
}//setup
void loop( void )
{
ExecuteStateMachine();
}//loop
#define INIT_WAIT 0
#define EXEC_NORMALLY 1
void ExecuteStateMachine( void )
{
static bool
bLed = false;
static unsigned long
timeExecute;
static byte
stateESM = INIT_WAIT;
unsigned long
timeNow;
switch( stateESM )
{
case INIT_WAIT:
if( millis() - timeSketchStart < 60000 )
return;
Serial.println( F("Initial delay done. Beginning execution." ) );
timeExecute = millis();
stateESM = EXEC_NORMALLY;
break;
case EXEC_NORMALLY:
timeNow = millis();
if( timeNow - timeExecute < 5000 )
return;
timeExecute = timeNow;
//do whatever needs doing every 5-seconds in here
//.
//.
//.
Serial.println( F("Execute...") );
bLed ^= true;
digitalWrite( pinLed, (bLed == true)?HIGH:LOW );
break;
}//switch
}//ExecuteStateMachine