Keypad Multi Password adding 3rd User

Hi,

Developing a propject through using this playground example

https://playground.arduino.cc/Main/MultiUserKeypadPassword

I’ve edited code as below,when i type 3rd password it says YANLIS SIFRE - WRONG PASSWORD, what am i missing ?

/* 
 || @version 1.0
 || @author Andrew Mascolo
 || @date May 9, 2013
 ||
 || @description
 || Simple use of keypad, password and LCD
*/
#include <Keypad.h>
#include <Wire.h> 
#include <LiquidCrystal.h>

LiquidCrystal lcd(53, 52, 51, 50, 49 , 48);
char Data[20]; // 20 is the number of chars it can hold
const byte Usercount = 3;

char Master[2][7] = {
  "184365",//alarmı kurar
  "994299"//alarmı kapatır
  "112233"//sirenleri acar test
};

char * User[Usercount] = {
  "DEVREDE","DEVRE DISI","TEST"};

byte currentCommand = 0;
byte MasterCount = 6;
byte good_Count = 0;

int user = 0;
bool Password_is_good, User_is_good;
char customKey;

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

char keys[ROWS][COLS] = 
{
    {'9','6','3'},
    {'8','5','2'},
    {'7','4','1'},
    {'*','0','#'}
};
byte rowPins[ROWS] = {2,3,4,5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {6,7,8}; //connect to the column pinouts of the keypad

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

void setup()
{
lcd.begin(16, 2);
lcd.setCursor(0,0);
lcd.print("SIFRENIZI GIRIN");
}

void loop()
{
  lcd.setCursor(0,0);
  lcd.print("SIFRENIZI GIRIN");
  customKey = customKeypad.getKey();
  if (customKey)
  {
    Data[currentCommand] = customKey;
    lcd.setCursor(currentCommand,1);
    lcd.print(Data[currentCommand]);
    currentCommand++;
  }

  if(currentCommand == MasterCount)
  {
    delay(1000);
    while(user != 2)
    {
      for(int count = 0; count < MasterCount; count++)
      {
        if(Data[count] == Master[user][count])
        {
          good_Count++;
        }  
      }
      if(good_Count == MasterCount)
      {
        good_Count = 0;
        Password_is_good = true; 
        break;
      }
      else
      { 
        good_Count = 0; 
        user++; 
        Password_is_good = false;
      }
    }

    lcd.setCursor(0,0);
    if(Password_is_good)
    {
      lcd.clear();
      lcd.print("+ SIFRE DOGRU +");
      lcd.setCursor(0,1);
      lcd.print(User[user]);
      delay(2000);
      user = 0;
      lcd.clear();
      clearData(); 
    }
    else 
    {
      lcd.clear();
      lcd.print("X YANLIS SIFRE X");
      lcd.setCursor(0,1);
      lcd.print(User[user]);
      delay(2000);
      user = 0;
      lcd.clear();
      clearData();
    }
  }
  if(customKey == '*')
  {
    lcd.clear();
    clearData();
    while(User_is_good != true)
    {
      lcd.setCursor(0,0);
      lcd.print("Change Password");
      lcd.setCursor(0,1);
      lcd.print("Enter User: ");
      user = customKeypad.getKey();
      if(user)
      {
        user -= '0'; // convert from char to int
        lcd.print(user);
        if(user < Usercount) 
        { // if within number of users
          delay(1000);
          User_is_good = true; //gets out of while loop
          user -= 1; // ENTER: 1 = master, 2 = user, but the array is 0 for master and 1 for user. This makes it so.
          lcd.clear();
        }
        else 
        {
          delay(1000);
          lcd.clear();
          lcd.print("Invalid User");
          delay(2000);
          lcd.clear(); 
        }
      } 
    }
    User_is_good = false;// stays in while loop
    while(customKey != '#')
    {
      lcd.setCursor(0,0);
      lcd.print(User[user]); // prints out the user
      lcd.setCursor(0,1);
      lcd.print("Press # to confirm");
      customKey = customKeypad.getKey();
      if (customKey)
      {
        Master[user][currentCommand] = customKey;
        lcd.setCursor(currentCommand,2);
        lcd.print(Master[user][currentCommand]);
        MasterCount = currentCommand;
        currentCommand++;
      }
    }
    if(customKey == '#') // press # to store new passwrd for user
    {
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print(User[user]);
      lcd.print(" is reset");
      delay(1000);
      clearData();
      lcd.clear();
    }
  }
}

void clearData() 
{
  user=0;
  while(currentCommand != 0)
  {   // This can be used for any array size, 
    Data[currentCommand--] = 0; //clear for new data
  }
  return;
}
char Master[2][7] =
{
  "184365",//alarmı kurar
  "994299"//alarmı kapatır
  "112233"//sirenleri acar test
};

Looks like you are trying to put 3 passwords in an array with only 2 row elements

UKHeliBob: char Master[2][7] = {   "184365",//alarmı kurar   "994299"//alarmı kapatır   "112233"//sirenleri acar test };

Looks like you are trying to put 3 passwords in an array with only 2 row elements

you are right, now it works, thanks :)

Just out of interest, how did you fix it ?

UKHeliBob: Just out of interest, how did you fix it ?

changed code parts as below;

const byte Usercount = 3;
char Master[3][7] = {
  "184365",//alarmı kurar
  "994299",//alarmı kapatır
  "112233"//sirenleri test moduna alır
};
char * User[Usercount] = {
  "DEVREDE","DEVRE DISI","TEST MODU"};
    while(user != 3)

Nice.

The whole idea of

const byte Usercount = 3

or

define Usercount 3

is to the use Usercount wherever the number of users is needed.

Then the next slob (or you!) who wants to change it just has to see the 3 and make it 4 in that one place.

Look at other 3s in your code, mebbe some 2s and 4s, for replacement potential with Usercount or Usercount +/- 1.

a7

Even better, let the compiler do the work

char Master[][7] = {
  "184365",//alarmı kurar
  "994299",//alarmı kapatır
  "112233"//sirenleri test moduna alır
};

byte userCount = sizeof(Master) / sizeof(Master[0]);

void setup() 
{
    Serial.begin(115200);
    Serial.println(userCount);
}

void loop() 
{
}

No need to change anything else when you add a new user to the array