Store keypad input data in variable

Hello, There!

I am trying to store 4x3 matrix keypad input data in variable, when pressing the switch without using keypad.h library. can anyone suggest me what changes i required to do?

Hardware Details:
1] Arduino Meag-2560
2] SPST Switch connected on pin 43 of arduino and GND with Pull-up resistor

Reference:
1] KEYPAD CONTROLLED LOCK USING ARDUINO WITHOUT LIBRARY

Source Code:

#include <LiquidCrystal.h>
String inputString;
float inputInt;
#define c2 26
#define c1 27
#define c0 28
#define r3 32
#define r2 31
#define r1 30
#define r0 29

LiquidCrystal lcd(38,37,36,35,34,33);

void setup() {
  lcd.begin(16,4);
  pinMode(c0, INPUT_PULLUP);
  pinMode(c1, INPUT_PULLUP);
  pinMode(c2, INPUT_PULLUP);

  pinMode(r0, OUTPUT);
  pinMode(r1, OUTPUT);
  pinMode(r2, OUTPUT);
  pinMode(r3, OUTPUT);
  pinMode(43, INPUT);
  digitalWrite (43,HIGH);
}
void loop() {
  char key1 = nfunc();
  if (key1) {
    lcd.print(key1);
    inputString +=key1;

  if (digitalRead(43)==LOW) 
    {
      //if (inputString.length() > 0) 
      //{
        inputInt = inputString.toFloat(); 
        inputString = "";
        lcd.setCursor(0,1);  //// Data In Variable               
        lcd.print(inputInt,4);
      //}
    }
  }
}

char nfunc(void) {
  char key = 'o';
  while (key == 'o')
    key = readkey();
  return key;
}

char readkey(void) {
  digitalWrite(r0, LOW);
  digitalWrite(r1, HIGH);
  digitalWrite(r2, HIGH);
  digitalWrite(r3, HIGH);
  if (digitalRead(c0) == LOW) {
    delay(500);
    return '3';
  }
  else if (digitalRead(c1) == LOW) {
    delay(500);
    return '2';
  }
  else if (digitalRead(c2) == LOW) {
    delay(500);
    return '1';
  }
  digitalWrite(r0, HIGH);
  digitalWrite(r1, LOW);
  digitalWrite(r2, HIGH);
  digitalWrite(r3, HIGH);
  if (digitalRead(c0) == LOW) {
    delay(500);
    return '6';
  }
  else if (digitalRead(c1) == LOW) {
    delay(500);
    return '5';
  }
  else if (digitalRead(c2) == LOW) {
    delay(500);
    return '4';
  }
  digitalWrite(r0, HIGH);
  digitalWrite(r1, HIGH);
  digitalWrite(r2, LOW);
  digitalWrite(r3, HIGH);
  if (digitalRead(c0) == LOW) {
    delay(500);
    return '9';
  }
  else if (digitalRead(c1) == LOW) {
    delay(500);
    return '8';
  }
  else if (digitalRead(c2) == LOW) {
    delay(500);
    return '7';
  }
  digitalWrite(r0, HIGH);
  digitalWrite(r1, HIGH);
  digitalWrite(r2, HIGH);
  digitalWrite(r3, LOW);
  if (digitalRead(c0) == LOW) {
    delay(500);
    return '-';
  }
  else if (digitalRead(c1) == LOW) {
    delay(500);
    return '0';
  }
  else if (digitalRead(c2) == LOW) {
    delay(500);
    return '.';
  }
  // (7)
  return 'o';
}

why reinvent the wheel?

@J-M-L can you suggest without keypad library ? It will be very helpful

Whatever I will suggest will boil down to implementing what the keypad library does: a function to monitor key states and presses and return the value.

So if you don’t want to use the library, extract the code from the library…

Once yo have a getKey() function that returns a key, you could have a look at the code in this post (thread is in French but code is code) and you’ll see how I collect keys into a buffer for further processing once you hit the end marker ‘#’