Menu that automatically exit after a while

As I make the menu will automatically exit after a while, that is if the user leaves. Like ATMs.

Let me give an example of basic menu, it is because I want to implement in my project

#include <Keypad.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(13, 12, 11, 10, 9, 8);

//Definición de filas y columnas
const byte Filas = 4; //Cuatro filas
const byte Cols = 4; //Cuatro columnas

//Definición de los pines
byte Pins_Filas[] = {3, 2, 1, 0}; //Pines Arduino para las filas
byte Pins_Cols[] =  {4, 5, 6, 7}; // Pines Arduino para las columnas


//Definición de las teclas
char Teclas [ Filas ][ Cols ] =
{
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};



Keypad kpd = Keypad(makeKeymap(Teclas), Pins_Filas, Pins_Cols, Filas, Cols);


char Teclado ()
{
  do {

    char Tecla = kpd.getKey();

    if (Tecla != NO_KEY)
    {
      return Tecla;
    }
  } while (1);
}


void setup() {
 lcd.begin(20, 4); //Configura el LCD con el numero de columas y filas. Para un LCD 16x4: 16 columnas y 4 filas.
 lcd.display(); //Enciende el display
 
}

void loop() {
 lcd.setCursor(0, 0); lcd.print("home"); //Imprime en la lcd
 
   
  char Tecla = kpd.getKey();
  
  if (Tecla == '*') {
     Menu();
  }
}

void Menu(){
     lcd.clear();
     lcd.setCursor(0, 0); lcd.print("Menu 1"); //Imprime en la lcd
     lcd.setCursor(0, 1); lcd.print("Menu 2"); //Imprime en la lcd 

     char kp = Teclado ();

      switch (kp) {
        case '1':
              lcd.clear();
              lcd.setCursor(0, 0); lcd.print("Submenu 1"); //Imprime en la lcd
              lcd.setCursor(0, 1); lcd.print("Submenu 2"); //Imprime en la lcd
              
              kp = Teclado ();
              switch (kp) {
                case '1':
                  lcd.clear();
                  lcd.setCursor(0, 0); lcd.print("Submenu 1"); //Imprime en la lcd
                  delay(100);
                  lcd.clear();
                break;

                case '2':
                        lcd.clear();
                        lcd.setCursor(0, 0); lcd.print("Submenu 2"); //Imprime en la lcd
                        delay(100);
                        lcd.clear();
                break;
              }
        break;

        case '2':
              lcd.clear();
              lcd.setCursor(0, 0); lcd.print("Menu 2"); //Imprime en la lcd
              delay(100);
              lcd.clear();
        break;
      }
}

Please help

(translate.google)

Save the millis() value when a menu is first shown, then each time through loop() compare the saved value with the current value of millis(). When the required interval has elapsed exit the menu.

UKHeliBob:
Save the millis() value when a menu is first shown, then each time through loop() compare the saved value with the current value of millis(). When the required interval has elapsed exit the menu.

Kind of?

https://www.arduino.cc/en/Tutorial/BlinkWithoutDelay

(translate.google)

Yes, using the same principle

new99:
https://www.arduino.cc/en/Tutorial/BlinkWithoutDelay

Exactly.

But reset the exit timer each time a user has pressed a button. Otherwise you will throw him out of the process regardless he is doing nothing or being active.

I am trying to do a condition that after 3 seconds out of the Menu or Submenu.

The user will have 3 seconds, if not push anything at that time is leaves and returns to the home.

#include <Keypad.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(13, 12, 11, 10, 9, 8);

//Definición de filas y columnas
const byte Filas = 4; //Cuatro filas
const byte Cols = 4; //Cuatro columnas

//Definición de los pines
byte Pins_Filas[] = {3, 2, 1, 0}; //Pines Arduino para las filas
byte Pins_Cols[] =  {4, 5, 6, 7}; // Pines Arduino para las columnas


//Definición de las teclas
char Teclas [ Filas ][ Cols ] =
{
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};



Keypad kpd = Keypad(makeKeymap(Teclas), Pins_Filas, Pins_Cols, Filas, Cols);


char Teclado ()
{
  do {

    char Tecla = kpd.getKey();

    if (Tecla != NO_KEY)
    {
      return Tecla;
    }
  } while (1);
}


void setup() {
 lcd.begin(20, 4); //Configura el LCD con el numero de columas y filas. Para un LCD 16x4: 16 columnas y 4 filas.
 lcd.display(); //Enciende el display
 
}

void loop() {
 lcd.setCursor(0, 0); lcd.print("home"); //Imprime en la lcd
 
   
  char Tecla = kpd.getKey();
  
  if (Tecla == '*') {
     Menu();
  }
}

void Menu(){
     
     //If user does not push anything in 3 seconds, it returns to the home
    //
    //

     lcd.clear();
     lcd.setCursor(0, 0); lcd.print("Menu 1"); //Imprime en la lcd
     lcd.setCursor(0, 1); lcd.print("Menu 2"); //Imprime en la lcd 

     char kp = Teclado ();

      switch (kp) {
        case '1':

                   //If user does not push anything in 3 seconds, it returns to the home
                  //
                 //
              lcd.clear();
              lcd.setCursor(0, 0); lcd.print("Submenu 1"); //Imprime en la lcd
              lcd.setCursor(0, 1); lcd.print("Submenu 2"); //Imprime en la lcd
              
              kp = Teclado ();
              switch (kp) {
                case '1':
                  lcd.clear();
                  lcd.setCursor(0, 0); lcd.print("Submenu 1"); //Imprime en la lcd
                  delay(100);
                  lcd.clear();
                break;

                case '2':
                        lcd.clear();
                        lcd.setCursor(0, 0); lcd.print("Submenu 2"); //Imprime en la lcd
                        delay(100);
                        lcd.clear();
                break;
              }
        break;

        case '2':
                   //If user does not push anything in 3 seconds, it returns to the home
                  //
                 //

              lcd.clear();
              lcd.setCursor(0, 0); lcd.print("Menu 2"); //Imprime en la lcd
              delay(100);
              lcd.clear();
        break;
      }
}

The problem here is that millis () does not increase

unsigned long interval=1000; // the time we need to wait
unsigned long previousMillis=0; // millis() returns an unsigned long.


void loop() {
   unsigned long currentMillis = millis();
   home();
}

void home(){
 
lcd.setCursor(0, 0); lcd.print("home"); //Imprime en la lcd
 
   
  char Tecla = kpd.getKey();
  
  if (Tecla == '*') {
     Menu();
  }

}


void Menu(){
     
  currentMillis = millis();

if ((currentMillis - previousMillis) >= interval) {
   previousMillis = millis();
   home();

}

     lcd.clear();
     lcd.setCursor(0, 0); lcd.print("Menu 1"); //Imprime en la lcd
     lcd.setCursor(0, 1); lcd.print("Menu 2"); //Imprime en la lcd 

     char kp = Teclado ();

      switch (kp) {
        case '1':

                   //If user does not push anything in 3 seconds, it returns to the home
                  //
                 //
              lcd.clear();
              lcd.setCursor(0, 0); lcd.print("Submenu 1"); //Imprime en la lcd
              lcd.setCursor(0, 1); lcd.print("Submenu 2"); //Imprime en la lcd
              
              kp = Teclado ();
              switch (kp) {
                case '1':
                  lcd.clear();
                  lcd.setCursor(0, 0); lcd.print("Submenu 1"); //Imprime en la lcd
                  delay(100);
                  lcd.clear();
                break;

                case '2':
                        lcd.clear();
                        lcd.setCursor(0, 0); lcd.print("Submenu 2"); //Imprime en la lcd
                        delay(100);
                        lcd.clear();
                break;
              }
        break;

        case '2':
                   //If user does not push anything in 3 seconds, it returns to the home
                  //
                 //

              lcd.clear();
              lcd.setCursor(0, 0); lcd.print("Menu 2"); //Imprime en la lcd
              delay(100);
              lcd.clear();
        break;
      }
}

The problem here is that millis () does not increase

That would be the end of the Arduino as we know it were it true, so I don't think that is the problem somehow.

What makes you think that millis() is not increasing ?

UKHeliBob:
That would be the end of the Arduino as we know it were it true, so I don't think that is the problem somehow.

void Menu(){
     
  currentMillis = millis();

if ((currentMillis - previousMillis) >= interval) {
   previousMillis = millis();
   home();

}

     lcd.clear();
     lcd.setCursor(0, 0); lcd.print("Menu 1"); //Imprime en la lcd
     lcd.setCursor(0, 1); lcd.print("Menu 2"); //Imprime en la lcd 

     char kp = Teclado ();

      switch (kp) {
        case '1':

                   //If user does not push anything in 3 seconds, it returns to the home
                  //
                 //
              lcd.clear();
              lcd.setCursor(0, 0); lcd.print("Submenu 1"); //Imprime en la lcd
              lcd.setCursor(0, 1); lcd.print("Submenu 2"); //Imprime en la lcd
              
              kp = Teclado ();
              switch (kp) {
                case '1':
                  lcd.clear();
                  lcd.setCursor(0, 0); lcd.print("Submenu 1"); //Imprime en la lcd
                  delay(100);
                  lcd.clear();
                break;

                case '2':
                        lcd.clear();
                        lcd.setCursor(0, 0); lcd.print("Submenu 2"); //Imprime en la lcd
                        delay(100);
                        lcd.clear();
                break;
              }
        break;

        case '2':
                   //If user does not push anything in 3 seconds, it returns to the home
                  //
                 //

              lcd.clear();
              lcd.setCursor(0, 0); lcd.print("Menu 2"); //Imprime en la lcd
              delay(100);
              lcd.clear();
        break;
      }
}

Condition not be how we do it, because the programme is waiting waiting to click a button through switch

Condition not be how we do it, because the programme is waiting waiting to click a button through switch

Sorry, but I can't make sense of that.