Hello,
I'm trying to make a big project where a user needs to input a 12 digit number using a keypad and then save that number into a variable for later use.
For now, i managed to write a code that takes the input from the user and then display it on LCD screen.
The code worked to be showing the number while inputing 10 digits and then when the user clicks on * or #, the LCD will show a message declaring the number
My problem is that whenever i enter more than 10 digits something happens and a totally different number appears,
I would really appreciate it if someone can help me figure out this problem
Here is my Code
#include <SoftwareSerial.h>
#include <String.h>
#include <LiquidCrystal.h>
#include <Keypad.h>
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {5, 4, 3}; //connect to the column pinouts of the keypad
LiquidCrystal lcd(A0, A1, A2, A3, A4, A5); //connecting the lcd
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup() {
// Setup size of LCD 20 characters and 4 lines
lcd.begin(20, 4);
lcd.setCursor(1,2);
lcd.setCursor(4,3);
lcd.setCursor(0,0);
Serial.begin(9600);
}
////////////////////////
unsigned long getKeypadIntegerMulti()
{
unsigned long IC = 0; // the number accumulator
unsigned long keyvalue; // the key pressed at current moment
int isnum;
do
{
keyvalue = kpd.getKey(); // input the key
isnum = (keyvalue >= '0' && keyvalue <= '9'); // is it a digit?
if (isnum) // if it is a digit then do this
{
lcd.print(keyvalue - '0');
IC = (IC * 10) + keyvalue - '0'; // accumulate the input number
}
} while (isnum || !keyvalue); // until not a digit or while no key pressed
lcd.clear();
lcd.print("Returning from funtion: ");
lcd.println(IC);
return IC;
}
void loop()
{
int val= getKeypadIntegerMulti();
Serial.println("Value is");
Serial.println(val);
delay(2500);
}
