converting keypad input to integer

Hello friends.I am a beginner and i am finding difficult in completing this project.
My project concept:
I have to enter password,once it is unlocked,i have t enter tool life,for example-50.When an external input count reaches 50,a buzzer should ring.This is all the concept.Please help me .

#define Password_Lenght 7
#include <Keypad.h>
#include<LiquidCrystal.h>
LiquidCrystal lcd(A0, A1, A2, A3, A4, A5);
int row[] = {9, 8, 7, 6};
int col[] = {5, 4, 3, 2};
int i, j, lcd_count, count = 1, key_id = 0, flag, entry = 0; // See About the Program
int col_scan;// Variable to identify a key press
char temp_press; // Variable to hold value of key press
char check[6], pass[6]; // See About the Program
int countnew = 0;




void setup()
{
  lcd.begin(16, 2);
  for (i = 0; i <= 3; i++)
  {
    pinMode(row[i], OUTPUT);
    pinMode(col[i], INPUT);
    digitalWrite(col[i], HIGH);
  }
  lcd.print("SET 5 Digit PASS");
}


/* Main Program Begins */

void loop()
{
  while (entry <= 4) // Password Setting Loop begins
  {
    SetPassword();
  }
  // Password Setting Loop Ends

  key_id = 0;
  keyscan(); // Scan for a Key Press

  /* Actions on Key Press begins */

  if (key_id == 1) // Condition to Check Key is Pressed
  {
    check[count] = temp_press;
    count++;

    /* Condition to Unlock Begins*/

    if (temp_press == 'A')
    {
      checkPassword();
      if (flag == 0)
      {
        lcd.setCursor(0, 0);
        lcd.print("SET-Toollife");

      } else {
        lcd.setCursor(0, 0);
        lcd.print("WRONG PASSWORD");
        delay(200);
        lcd.clear();
        lcd.print("LOCKED");
      }
      count = 1; // Resetting the counter variable
    }

    /* Condition to Unlock Ends*/

    /* Condition to Change Password Begins */

    else if (temp_press == 'C')
    {
      checkPassword();
      if (flag == 0)
      {
        lcd.setCursor(0, 0);
        lcd.print("ENTER NEW PASS");
        key_id = 0;
        entry = 0;
      } else {
        lcd.setCursor(0, 0);
        lcd.print("WRONG PASSWORD");
      }
      count = 1; // Resetting the counter variable
    }

    /* Condition to Change Password Ends */

    /* Condition to LOCK Begins*/

    else if (temp_press == 'B')
    {
      lcd.setCursor(0, 0);
      lcd.print("LOCKED");
      count = 1; // Resetting the counter variable
    }
    /* Condition to LOCK Ends*/
  }

  /* Actions on Key Press Ends*/
}

/* Main Program Ends */


void SetPassword() // Subroutine to SET User Defined Password
{
  keyscan();
  if (key_id == 1)
  {
    if (temp_press == 'A' || temp_press == 'C' || temp_press == 'B') // Condition to Check for an Invalid Keypress
    {
      lcd.setCursor(0, 0);
      lcd.print("INVALID KEYS");
      entry = 0;
    }
    else

    {
      pass[entry] = temp_press;

    }
  }
  key_id = 0;
  if (entry == 5)
  {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("PASSWORD SET & LOCKED");
  }
} // Subroutine to SET Password ENDS

char keyscan()// Subroutine to Scan Keypad for a Keypress
{
  for (i = 0; i <= 3; i++)
  {
    digitalWrite(row[0], HIGH);
    digitalWrite(row[1], HIGH);
    digitalWrite(row[2], HIGH);
    digitalWrite(row[3], HIGH);
    digitalWrite(row[i], LOW);
    for (j = 0; j <= 3; j++)
    {
      col_scan = digitalRead(col[j]);
      if (col_scan == LOW)
      {
        key_id = 1;
        entry++;
        temp_press = keypress(i, j);
        lcd.setCursor(lcd_count++, 1);
        lcd.print(temp_press);
        if (temp_press == 'A' || temp_press == 'C' || temp_press == 'B')
        {
          lcd_count = 0;
          lcd.clear();
        }
        delay(300);
        break;
      }
    }
  }
}// Subroutine to Scan Keypress Ends

char keypress(int i, int j) // Subroutine to Identify the value of Key pressed
{
  if (i == 0 && j == 0)
  {
    return ('1');
  }
  if (i == 0 && j == 1)
  {
    return ('2');
  }
  if (i == 0 && j == 2)
  {
    return ('3');
  }
  if (i == 0 && j == 3)
  {
    return ('A');
  }
  if (i == 1 && j == 0)
  {
    return ('4');
  }
  if (i == 1 && j == 1)
  {
    return ('5');
  }
  if (i == 1 && j == 2)
  {
    return ('6');
  }
  if (i == 1 && j == 3)
  {
    return ('B');
  }
  if (i == 2 && j == 0)
  {
    return ('7');
  }
  if (i == 2 && j == 1)
  {
    return ('8');
  }
  if (i == 2 && j == 2)
  {
    return ('9');
  }
  if (i == 2 && j == 3)
  {
    return ('C');
  }
  if (i == 3 && j == 0)
  {
    return ('*');
  }
  if (i == 3 && j == 1)
  {
    return ('0');
  }
  if (i == 3 && j == 2)
  {
    return ('#');
  }
  if (i == 3 && j == 3)
  {
    return ('D');
  }
} // Subroutine to identify Keypress Ends

void checkPassword() // Subroutine to Check User Input Data with SET Password
{
  flag = 0;
  for (i = 1; i <= 5 && flag == 0; i++)
  {
    if (check[i] == pass[i])
    {
      flag = 0;
    }
    else
    { flag = 1;
    }
  }
} // Subroutine to check password ends
char keyscan()// Subroutine to Scan Keypad for a Keypress
{

This function says that it will return a character. It does not abide by that promise by actually returning anything.

That function uses a lot of variables that are global in scope that do not need to be global. Move all variables that are used only by the keyscan() function INTO the keyscan() function. Loop indices do not make sense as global variables.

Make the function properly return the key that was pressed.

Get any code that deals with the LCD out of that function. Until that is done, it is a waste of time trying to fix the rest of the program that uses that function.

#include <Keypad.h>

I don’t understand why you include the “Keypad” library, then re-invent the wheel and never use the library.

Most of your keypad code could be replaced by a couple of calls to the Keypad library.

Once the library is properly initialised, all you need to read a keypress is:-

char c = keypad.getKey();

If a 4x4 keypad is connected and pressing 1 will give what ? i want an integer 1 then what should i do?

If a 4x4 keypad is connected and pressing 1 will give what ?

That depends on your code, which it seems you forgot to post.

#include <Keypad.h>


const byte ROWS = 4; //four rows

const byte COLS = 4; //three columns

char keys[ROWS][COLS] = {

  {'1','2','3','A'},

  {'4','5','6','B'},

  {'7','8','9','C'},

  {'*','0','#','D'}

};

byte rowPins[ROWS] = {2, 3, 4, 5}; //connect to the row pinouts of the keypad

byte colPins[COLS] = {6, 7, 8, 9}; //connect to the column pinouts of the keypad



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



void setup(){

  Serial.begin(9600);

}

void loop(){

  char key = keypad.getKey();

  if (key){

  Serial.println(key);

  }
  
}

In this code if 1 is pressed on 4x4 keypad then the output on Serial monitor will be an ASCII 1?

kewalpasad:

#include <Keypad.h>

const byte ROWS = 4; //four rows

const byte COLS = 4; //three columns

char keys[ROWS][COLS] = {

{‘1’,‘2’,‘3’,‘A’},

{‘4’,‘5’,‘6’,‘B’},

{‘7’,‘8’,‘9’,‘C’},

{’*’,‘0’,’#’,‘D’}

};

byte rowPins[ROWS] = {2, 3, 4, 5}; //connect to the row pinouts of the keypad

byte colPins[COLS] = {6, 7, 8, 9}; //connect to the column pinouts of the keypad

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

void setup(){

Serial.begin(9600);

}

void loop(){

char key = keypad.getKey();

if (key){

Serial.println(key);

}
 
}




In this code if 1 is pressed on 4x4 keypad then the output on Serial monitor will be an ASCII 1?

But bro how to get int x value as value of keyword pressed.

But bro how to get int x value as value of keyword pressed.

The keypad library does not have to return '1'. It could return 'S', instead. Or, 5.

But, if you follow convention, and have the library return a '1' when the key labeled 1 is pressed, and you want a 1, instead, look at an ASCII table. What is '1' - '0'?