Skip to main content
added 122 characters in body
Source Link
ratchet freak
  • 3.3k
  • 1
  • 13
  • 13

If you rewrite the code to be a state machine so that loop() never blocks it's pretty easy to add:

bool paused = false;
void loop(){
    //read button
    if(buttonPressed){
        paused = !paused;
    }
    if(paused){
        return;
    }
    //rest of code written so it never blocks and returns as fast as possible
}

Then the resume part is handled by the extra already required by needing to be able resume on next call of loop.

If you go for full power off then you need to write out your state to non-volatile memory and read it back in on init.

If you rewrite the code to be a state machine so that loop() never blocks it's pretty easy to add:

bool paused = false;
void loop(){
    //read button
    if(buttonPressed){
        paused = !paused;
    }
    if(paused){
        return;
    }
    //rest of code written so it never blocks and returns as fast as possible
}

Then the resume part is handled by the extra already required by needing to be able resume on next call of loop.

If you rewrite the code to be a state machine so that loop() never blocks it's pretty easy to add:

bool paused = false;
void loop(){
    //read button
    if(buttonPressed){
        paused = !paused;
    }
    if(paused){
        return;
    }
    //rest of code written so it never blocks and returns as fast as possible
}

Then the resume part is handled by the extra already required by needing to be able resume on next call of loop.

If you go for full power off then you need to write out your state to non-volatile memory and read it back in on init.

Source Link
ratchet freak
  • 3.3k
  • 1
  • 13
  • 13

If you rewrite the code to be a state machine so that loop() never blocks it's pretty easy to add:

bool paused = false;
void loop(){
    //read button
    if(buttonPressed){
        paused = !paused;
    }
    if(paused){
        return;
    }
    //rest of code written so it never blocks and returns as fast as possible
}

Then the resume part is handled by the extra already required by needing to be able resume on next call of loop.