Spark.Sleep(pin, mode) and delay function [SOLVED]

When you call the sleep function with a delay right after, the delay is skipped after waking from sleep.

For example:

void loop() {
    Spark.sleep(D2, RISING);

    //wait 10 seconds after wake up
    delay(10000);  
}

The delay is skipped. How could I get the functionality of implementing a blocking delay directly after waking from sleep?

Thank you in advance :slight_smile:

Try to split your long delay into one first short one to โ€œskipโ€ and a longer one. This might then get executed correctly.

To find out the reason for this behaviour one would need to dive deeper into the whole topic.

Hey ScruffR do you think itโ€™s because the delay should come before the sleep call? I was thinking maybe when the core wakes up it starts over at the beginning of the loop and not where the call left off. Iโ€™ll test this once Iโ€™m home and if that fails I will test what you said to try.

Are you definitely using a Core?

On the core, the docs, have this to say:

the device is reset and run all user code from the beginning with no values being maintained in memory from before the stop mode. source

So on the core the device is restarted from the beginning. On the Photon, the device will resume from where it stopped.

Cheers,
M.

Yes I definitely am using a core and you are 100% correct :slight_smile: this issue is resolved. The core starts over again, so the sleep call needs to be at the end of the code.

1 Like