How to make instant stop button in the keypad.h library

hi :),

I would like to help me for the below
If I pressed ‘1’ key the Arduino will do some actions for 60 seconds , I want to be able to stop these action instantly while it’s running by pressing ‘2’ key

I know that to make the loop stop or reset it, i can use void (*resetloop)(void)=0;
but I don’t know how to make it work, I tired a lot with (while) function but no luck . help the newbie please :slight_smile:

#include <Keypad.h>

const byte ROWS = 4; 
const byte COLS = 4;
char hexaKeys[ROWS][COLS] = {
  {'0','1','2','3'},
  {'4','5','6','7'},
  {'8','9','A','B'},
  {'C','D','E','F'}
};
byte rowPins[ROWS] = {3, 2, 1, 0}; 
byte colPins[COLS] = {7, 6, 5, 4}; 

//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); 

void setup(){
  Serial.begin(9600);
}
  
void loop(){
  char customKey = customKeypad.getKey();
  
  if (customKey=='1'){
    //done some actions which will take 60 second 
  }
}

I know that to make the loop stop or reset it, i can use

But, you shouldn't. Resetting the software on the Arduino is not the same as resetting the hardware. What you should do is properly stop whatever needs stopping.

What you REALLY should do is delete the page of delay() from your repertoire. That function has NO place in responsive code.

As it is, the code you posted does nothing, and cares not a whit about any key other than '1'.

Ready, study, and embrace (particularly this step), the blink without delay example. Write your code so that on every pass through loop, you see if you need to start or stop doing something. If so, start it or stop it. Do not use delay() to make something stop at the appropriate time.

What you REALLY need to do is YOUR HOMEWORK. You need to research the subject yourself instead of coming here without a clue. We are here to help people learn, not to do their homework so you can play. Google "millis" Look at Blinkwithoutdelay.

Look at the variables in the example:

  // Variables will change:
int ledState = LOW;             // ledState used to set the LED
long previousMillis = 0;        // will store last time LED was updated

// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long interval = 1000;           // interval at which to blink (milliseconds)

Look at the rest of the example:

// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long interval = 1000;           // interval at which to blink (milliseconds)

void setup() {
  // set the digital pin as output:
  pinMode(ledPin, OUTPUT);      
}

void loop()
{
  // here is where you'd put code that needs to be running all the time. (WHAT DOES THIS SAY ?)

  // check to see if it's time to blink the LED; that is, if the                        (WHAT DOES THIS SAY ?)
  // difference between the current time and last time you blinked         (WHAT DOES THIS SAY ?)
  // the LED is bigger than the interval at which you want to                   (WHAT DOES THIS SAY ?)
  // blink the LED.                                                                                              (WHAT DOES THIS SAY ?)
  unsigned long currentMillis = millis();

  if(currentMillis - previousMillis > interval) {                                           // (WHAT DOES THIS MEAN ?)
    // save the last time you blinked the LED                                            //  (WHAT DOES THIS SAY ?)
    previousMillis = currentMillis;                                                              // (WHAT DOES THIS MEAN ?)

    // if the LED is off turn it on and vice-versa:                                    // ETC.ETC.ETC....
    if (ledState == LOW)
      ledState = HIGH;
    else
      ledState = LOW;

    // set the LED with the ledState of the variable:
    digitalWrite(ledPin, ledState);
  }
}

PLEASE DON'T GROVEL LIKE THIS ANY MORE...

. help the newbie please

We have a "NO Grovelling " Policy on the forum. (first of all it's dead givaway that it is most likely some lazy person who doesn't want to do their homework)

Step-#1 Make a Google "TO DO "list Step-#2 Google your objective Step-#3 Click on Google hits that include a URL that begins with this "www.arduino.cc/en/Tutorial" like this one:

www.arduino.cc/en/Tutorial/BlinkWithoutDelay Look at this Google search. Note how the arduino forum is at the top of the list . Why ? Could it be because I put the word "arduino" at the beginning of ALL MY GOOGLE SEARCHES ? http://www.bing.com/search?q=arduino+blink+without+delay&qs=SC&sk=SC1&pq=arduino+blinkwi&sc=8-15&sp=2&FORM=QBRE&cvid=038d87a6a41643809e4b53f29fe5f651

Experiment with the blinkwithout delay using the values you need for your program and after you test it, copy and paste it into your program.

Have a look at this tutorial: http://www.instructables.com/id/Access-control-with-Arduino-Keypad-4x4-Servo/step5/And-now-the-programming

PaulS and raschemmel ,I appreciate your reply and feedback. i will do my homework I wasn't meant to be lazy. and no grovel again ....... I will do my beast and i will feedback later.