wait 30 seconds unless

i need to send a message when an action happens but i also need the option to cancel this message in 30 seconds if needed

i have this at the moment how can i interrupt it with a button press from a touch screen

void sendmessage() {
  PlayButtonPress();
    //is the time Up Before Reset
  if (millis() - lastMillis >= 1 * 30 * 1000UL)
  {
    lastMillis = millis(); //get ready for the next iteration
    Serial.print("Sending Message");
          if (!fona.sendSMS(Phone1, Message1)) {
        Serial.println(F("Failed"));
      } else {
        Serial.println(F("Sent!"));
      }
  }

}

the code th detect the button press is

  if (Event.reportObject.cmd == GENIE_REPORT_EVENT)
  {
    if (Event.reportObject.object == GENIE_OBJ_USERBUTTON) // If a button was pressed
    {
      if (Event.reportObject.index == 3) //  Cancel was pressed   
      {
        // Execute your function
        Serial.print("Button3 Pressed");
        
      }
    }
  }

Post the complete program. It is too difficult to make sense of snippets.

If it is too long add the .ino file as an attachment.

Do you mean that you want to press SEND but the Arduino waits 30secs before actually sending the message?
Or do you want to be able to send a follow-up CANCEL message within 30 secs, but not later?

...R

i need to send a message when an action happens but i also need the option to cancel this message in 30 seconds if needed

Could you clarify this please.
If the message is already sent / gone how can you cancel it?

the person presses a remote button and if he or she has pressed it by mistake the system will speak and say "u have pressed the send message button if this was a mistake please press the cancel button on the screen if not the message will go in 30 seconds"

i can't post all the code as the rest has nothing to do with the button press or cancel

i am after a way to interrupt the 30 second countdown

Blink without delay.

I can't post the rest of my answer, because it has nothing to do with your installation.

The logic needs to be something like this

void loop() {
   if send button is pressed and readyToGo == false
      readyToGo = true
      save the value of millis()
   if cancel is pressed
       readyToGo = false;
  if (millis() - savedValue >= interval && readyToGo == true) {
     // send message
  }
}

...R

mikewitney:
i can't post all the code

Can't, or won't?

as the rest has nothing to do with the button press or cancel

Let's see the rest of the code so we can judge that for ourselves.

mikewitney:
the person presses a remote button and if he or she has pressed it by mistake the system will speak and say "u have pressed the send message button if this was a mistake please press the cancel button on the screen if not the message will go in 30 seconds"

i can't post all the code as the rest has nothing to do with the button press or cancel

i am after a way to interrupt the 30 second countdown

Thanks for the clarification.

Is your program doing anything else while waiting for the 30 seconds timeout?

If NOT use do / while and keep checking the timeout and reading the cancel button.

If you cannot stop the process using do/ while you could use external interrupt and hardware timer, or just "blink without delay " as suggested ( surprise!).

the system really didn't have to run anything else as long as it can detect a screen press which is a function in itself.

and i'm not being funny but there isn't anything else to post unless you need to know how i am playing sounds or you need to know the code for Fona as thats all else there is or how to draw graphics on my touch screen.

this cancel within 30 seconds is a new add on. i just didn't know how to approach it..
so sorry if i sounded rude i wasn't trying to be

thanks for responses

do / while sounds a good approach to me thanks again

mikewitney:
the system really didn't have to run anything else as long as it can detect a screen press which is a function in itself.

and i'm not being funny but there isn't anything else to post unless you need to know how i am playing sounds or you need to know the code for Fona as thats all else there is or how to draw graphics on my touch screen.

this cancel within 30 seconds is a new add on. i just didn't know how to approach it..
so sorry if i sounded rude i wasn't trying to be

thanks for responses

do / while sounds a good approach to me thanks again

No I did not take your response as rude. Basically I do not like to ask "what are you building", it is personal (none of my business) and generally irrelevant.
I just needed some specifics ( and was avoiding the "standard" do not use delay () ) . That's all.

I just look at do/ while as a delay() on steroids Ha Ha

Vaclav:
I just look at do/ while as a delay() on steroids Ha Ha

'do..while" is just like "while...", except the body is always executed at least once.

I can't imagine where the steroids come into it.

mikewitney:
the system really didn't have to run anything else as long as it can detect a screen press which is a function in itself.

and i'm not being funny but there isn't anything else to post unless you need to know how i am playing sounds or you need to know the code for Fona as thats all else there is or how to draw graphics on my touch screen.

Let's take a look at your code again:

void sendmessage() {
  PlayButtonPress();
    //is the time Up Before Reset
  if (millis() - lastMillis >= 1 * 30 * 1000UL)
  {
    lastMillis = millis(); //get ready for the next iteration
    Serial.print("Sending Message");
          if (!fona.sendSMS(Phone1, Message1)) {
        Serial.println(F("Failed"));
      } else {
        Serial.println(F("Sent!"));
      }
  }

}

In order for this sendmessage() function to do anything, you must call it from elsewhere in your code. That is to say, there must be a line elsewhere in your code that looks like this:

  sendmessage();

This is why we wanted to see the rest of your code. We want to know: from where is this sendmessage() function used? This is because, if you don't want the message sent, the most straightforward way to prevent it from being sent would probably involve calling sendmessage() if and only if: (a) there is a message to be sent, and (b) right now it is time to send it. In order to help you do this, we need to see the rest of your code.

  if (Event.reportObject.cmd == GENIE_REPORT_EVENT)
  {
    if (Event.reportObject.object == GENIE_OBJ_USERBUTTON) // If a button was pressed
    {
      if (Event.reportObject.index == 3) //  Cancel was pressed   
      {
        // Execute your function
        Serial.print("Button3 Pressed");
       
      }
    }
  }

What is this "Event"? Are you using some kind of library for this?
Where does this snippet appear in your code? In loop()? In an interrupt?

this cancel within 30 seconds is a new add on. i just didn't know how to approach it..
so sorry if i sounded rude i wasn't trying to be

You weren't being rude, just unhelpful.

mikewitney:
the system really didn't have to run anything else as long as it can detect a screen press which is a function in itself.

Does this function have a name? How is it accessed?

and i'm not being funny but there isn't anything else to post unless you need to know how i am playing sounds or you need to know the code for Fona as thats all else there is or how to draw graphics on my touch screen.

I have no idea what Fona even is. And you might be right: it might not even matter.
And as for how you are playing sounds: that, too, might not matter, unless it causes the rest of your program to lock up when a sound is playing. (Does it?)
And as for how to draw graphics: yes, that would be helpful. After all, you probably don't want your "CANCEL" button to appear unless there is something to cancel. And when it is pressed, and there is something to cancel, it would be helpful to have some kind of confirmation (the words "Message cancelled" or something similar).

You seem to underestimate the extent to which different parts of a program depend on each other. This underestimation is probably at the root of your problem.