Pause and un pause using a push button

Hello,

I currently am able to use a push button to end the program using debounce.
(Code below)

const byte ButtonPin = 5;
bool logFlag = true;// default status  to start writing data to card

void buttonCheck()//debounced function to check if button pressed
{
  button.update();
  if (button.fell())
  {
    if (logFlag == true)
    {
      logFlag = false;
      
    }
  }
}
  buttonCheck();//update logFlag

  if (logFlag)// logFlag determines writing to  card
  {
    File file = SD.open(filename, FILE_WRITE);
    if (file)
    {
       Serial.print(value of sensor);
      }

I want to use a push button to pause when it is pressed once and when it is pressed gain, I want it to resume.
When pressed once, pause for 5 min and if the button is pressed again before 5 min , resume the code. If the button is not pressed again even after 5 min , end the program.

How do I do this?

Thank you!

What exactly do you mean by "stop the code" ?
Providing your complete program (like Attach) will help to understand your code :wink:

I meant ending the program !

novice123:
I meant ending the program !

As long as the Arduino has power, the program is running.

You can STOP your logic with a switch, as you have stated, but cannot stop the Arduino program.

Paul

Yes! Thank you for putting it correctly. The logic stops when I am using this code using debounce ()

const byte ButtonPin = 5;
bool logFlag = true;// default status  to start writing data to card

void buttonCheck()//debounced function to check if button pressed
{
  button.update();
  if (button.fell())
  {
    if (logFlag == true)
    {
      logFlag = false; // stops writing to the card
      
    }
  }
}
  buttonCheck();//update logFlag

  if (logFlag)// logFlag determines writing to  card
  {
    File file = SD.open(filename, FILE_WRITE);
    if (file)
    {
       Serial.print(value of sensor);
      }

If I need a single push button to pause and also resume( When pressed once, pause for 5 min and when pressed gain resume writing and when pressed again, pause...) how should I do it?
Also, if the button is pressed before 5 mins are over, the program should resume and continue. if the button is not pressed before the end of 5 min, the logic should end.

Any hints on how to do this?

Thank you!

If you want to be able to prevent some code from running (or permit it) when a button is pressed use the button to change the state of a variable - something like this pseudo code

if (buttonState == LOW and previousButtonState == HIGH) { // assumes LOW when pressed)
  if (permissionToRun == false) {
    permissionToRun = true;
  }
  else {
    permissionToRun = false;
  }
}

if (permissionToRun == true) {
   // code that you want to run
}

…R