This tutorial shows how to put the arduino to sleep and use a watchdog to wake up at intervals:
I been studding c++ and as I am getting better I am instantiating objects with the new
keyword. I have learned that if you create something with the new
keyword you are responsible for deleting it from memory when you no longer needed. But I do not know if this applies when you put arduino to sleep.
Anyways my question is in the comments of the code:
Foo * someObject;
void setup()
{
someObject = new Foo(arg1, arg2, ..); // crete an instance of someObject
// init pins etc..
}
void loop()
{
if(button1Pressed())
{
// **** DO I HAVE TO DELETE OBJECTS BEFORE GOING TO SLEEP? Do I need this line? ****
delete someObject;
gotToSleepAndWakeUpIn4Seconds() ; // places arduino in sleep mode and wakes up again in 4 seconds
int x = 0; // this line never executes arduino is on sleep mode and will wake up again in 4 seconds
}
// more code
if(something)
someObject->executeFunction1();
// etc...
// ....
}