Keypad Password

Just a little help guys, i am using arduino mega 2560, 4x4 keypad, and 20x4 lcd.
i wanted to have a code that when i press '*' or '#' on the keypad, the program will clear the screen and put a message "Enter Pass code:" and i can press all the numbers on my keypad. My problem is i am using a switch case:

void keypadEvent(KeypadEvent key){
  switch (keypad.getState()){
 case RELEASED:
     switch (key){
        case '*':
        lcd.setCursor(0,1);
        lcd.print("Enter Password:");
        lcd.setCursor(0,2);
        lcd.print(key);
        break;
     }
  }
}

when i press '*' the message pops up but i cant press the all other keys..

thanks for the help guys XD

Start here

The only time that you display the keypress received is if it is a *. You need to displaythe received character if it is not a * but only after the * has been received.

What code can you suggest UKHeliBob?

Before suggesting any code or ideas on how you should write it can you please post all of your current code as advised in the link that AWOL gave you.

here is the code.. my problem is on the password part.. thank you in advance..

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

LiquidCrystal lcd(12, 11, 37, 35, 33, 31, 29, 27, 25, 23);

int backlight = 41;
boolean ledPin_state;

const byte ROWS = 4;
const byte COLS = 4; 

char keys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};

byte colPins[COLS] = { 44, 42, 40, 38 };

byte rowPins[ROWS] = { 52, 50, 48, 46 }; 

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup()
{
    Serial.begin(9600);
    lcd.begin(20,4);
    pinMode(backlight, OUTPUT);
    digitalWrite(backlight, HIGH);
    ledPin_state = digitalRead(backlight);   
    keypad.addEventListener(keypadEvent); 
}

void loop()
{
  char key = keypad.getKey();
}

void keypadEvent(KeypadEvent key){
  switch (keypad.getState);
   case PRESSED:
      switch (key){
        case 'B':
          if (key == 'B') {
            digitalWrite(backlight,!digitalRead(backlight));
            ledPin_state = digitalRead(backlight);
          }
          break;
          
        case '*':
         if (key == '*'){
         lcd.clear();
         lcd.setCursor(0,1);
         lcd.print("Enter Pass Code:");
         lcd.setCursor(0,2);
        lcd.print (key);
         }
}
    switch (keypad.getState);
   case PRESSED:
      switch (key){
      case '*':
         if (key == '*'){

How could key possibly NOY be '' in that '" case? Your first switch statement is not correct. The switch statement does not end with a ;, and it DOES have { and }. And, no, the { is NOT supposed to be jammed up against the end of the statement!

my problem is on the password part.

And, what is the problem? Aside from the fact that you haven't written any code? There is a Password library that might possibly be useful.

sorry wrong code.

here is my code..

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

LiquidCrystal lcd(12, 11, 37, 35, 33, 31, 29, 27, 25, 23);

int backlight = 41;
boolean ledPin_state;

const byte ROWS = 4;
const byte COLS = 4; 

char keys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};

byte colPins[COLS] = { 44, 42, 40, 38 };

byte rowPins[ROWS] = { 52, 50, 48, 46 }; 

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup()
{
    Serial.begin(9600);
    lcd.begin(20,4);
    pinMode(backlight, OUTPUT);
    digitalWrite(backlight, HIGH);
    lcd.clear();
    ledPin_state = digitalRead(backlight);   
    keypad.addEventListener(keypadEvent); 
}

void loop()
{
  char key = keypad.getKey();
}

void keypadEvent(KeypadEvent key){
  switch (keypad.getState()){
    case PRESSED:
      switch (key){
        case 'B':
          if (key == 'B') {
            digitalWrite(backlight,!digitalRead(backlight));
            ledPin_state = digitalRead(backlight);
          }
          break;
          
       case '*':
         if (key == '*'){
           lcd.setCursor(0,1);
           lcd.print("Enter Pass Code:");
           lcd.setCursor(0,2);
           lcd.print(key);
         }
      }
  } 
}

what i want here is, if the user presses '' the user should enter his/her password (he/she can press any key, in this case i cannot because only '' is recognized) and after entering the correct password he/she must press the '*' again to verify his/her password.. thank you for the kind help :slight_smile: