KEYPAD LIBRARY

hello evrybody i want to know how i can command the time of function key=mykeypad.waitForKey();
because the programm still not working untill i press a button
sorry for The language :slight_smile:

i want to know how i can command the time of function

Simple. Don't use waitForKey() if you don't want to wait indefinitely.

because the programm still not working

What program?

void loop() {
flag = true;

lcd.clear();
lcd.print(“Password:”);

for(int i = 0; i < sizeof(password); i++){

char key = myKeypad.waitForKey();
if(key != password*){*

  • flag = false; *
  • }*

_ lcd.print("*");_

  • }*
    the program still not working untill i press a key button but i would to make a method to limit the waitForKey in (10s) :frowning:
unsigned long startLooking = millis();

while(millis() - startLooking <= 10000){
    //  use getKey and do your key stuff in here
    //  if you get a key use break to escape the while loop
}

Can you please clarify more :slight_smile:

Clarify what? What’s the question?

so how the program becomes

MAK93:
so how the program becomes

I'm not going to write the program for you. I don't even have enough of your original program to begin trying to do that for you. If you have a specific question about how to do it then I'll gladly answer. But it is time for you to try now. What part don't you understand?

Code tags please! Thanks - Moderator.

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

// Keypad
const byte ROWS = 4; //four rows
const byte COLS = 3; //four columns

//define the cymbols on the buttons of the keypads
char keymap[ROWS][COLS] = {
 {'1','2','3'},
 {'4','5','6'},
 {'7','8','9'},
 {'*','0','#'}
};

byte rowPins[ROWS] = {0, 1, 2, 3}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {4, 5, 6}; //connect to the column pinouts of the keypad

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


// create and initialize the LCD object
// LiquidCrystal(rs, enable, d4, d5, d6, d7)
LiquidCrystal lcd(8, 9, 10, 11, 12, 13);

char password[] = {'0', '0', '0','0', '0', '0'};
boolean flag;

void setup() {  
 lcd.begin(16, 2);  
 lcd.cursor();
}

void loop() {
 flag = true;
 
 lcd.clear();
 lcd.print("Password:");
 
 for(int i = 0; i < sizeof(password); i++){
   
   char key = myKeypad.waitForKey();
   if(key != password[i]){
     flag = false;  
   }
   
   lcd.print("*");
   
 }

 lcd.setCursor(0 ,1);
 
 if(flag == false){    
   lcd.print("Incorrect !!");
 }else{
   lcd.print("Correct");
 }

 delay(300);
}

this is all of the sketch but the proble is how ican make a delay when Lack of pressure because the function waitForKey interrupt them to make delay

Code tags. Please use code tags so your code doesn't end up in half itallics.

How To Use This Forum

See point #7