Hi I have a little project which I need to request a number the user enters it on the keypad and a function to convert the characters to an integer. (getKeypadIntegerMulti() ) This function works good except it can only go to 32760 but thats probably a variable type. that I can figure out later but the issue I am having is if I use the LCD with that funtion the function stops work when you press the 4 key.I have no idea why this is happening. I will upload my code so maybe someone can see what I am doing wrong or something is not compatable.
#include <Key.h>
#include <Keypad.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
char skey;
const byte ROWS = 4;
const byte COLS = 3;
char numTurns;
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'},
};
byte rowPins[ROWS] = {2,3,4,5};
byte colPins[COLS] = {6,7,8};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 20, 4);
void setup()
{
// initialize the LCD
lcd.begin();
// Turn on the blacklight and print a message.
lcd.backlight();
lcd.setCursor(0,0);
lcd.print("Welcome to Pierre's");
lcd.setCursor(4,1);
lcd.print("Master Wind");
lcd.setCursor(0,3);
lcd.print("Press any key");
//setWaitforKey();
}
//********************* END Setup ****************
int getKeypadIntegerMulti()
{
int value = 0; // the number accumulator
int keyvalue; // the key pressed at current moment
int isnum;
Serial.println("Enter the digits,press any non-digit to end ");
Serial.print("You have typed: ");
do
{
keyvalue = keypad.getKey(); // input the key
isnum = (keyvalue >= '0' && keyvalue <= '9'); // is it a digit?
if (isnum)
{
Serial.print(keyvalue - '0');
value = value * 10 + keyvalue - '0'; // accumulate the input number
//Serial.println("Lets accumulate the number");
}
} while (isnum || !keyvalue); // until not a digit or while no key pressed
//
Serial.println(" ");
Serial.print("Returning from funtion: ");
Serial.println(value);
return value;
}// END getKeypadInteger
void setWaitforKey(){
skey = keypad.waitForKey();
//Serial.println(skey);
}
void loop()
{
//mainMenu();
int val= getKeypadIntegerMulti();
Serial.println("Value is");
Serial.println(val);
delay(1000);
}
