Dear all, with a keypad and LCD interfaced to the arduino mega I have managed to display what the user presses on the LCD. My problem is here; if for example the user writes 0043 - this value is saved into an array;
How can I save this value as a whole in a variable ??
This is the code used:
//Display refernce no on lcd
for(int x =0; x<4;x++) //loop to save amount entered (4 digit no)
{
do
{
reference_no = customKeypad.getKey(); //get amount from keypad
Serial.println(reference_no); //serial print for testing
if(reference_no == 0) //amount is always 0 when waiting for key to get pressed
{
flag = true;
}
else if((reference_no == '0')||(reference_no == '1') ||(reference_no == '2')||(reference_no == '3')
|| (reference_no == '4') || (reference_no == '5') || (reference_no == '6') || (reference_no == '7')
|| (reference_no == '8') || (reference_no == '9')) //for pressing any digit no
{
reference_no = reference_no - 48; //since from keypad, the characters are displayed as ASCII
lcd.setCursor(x,0); //move cursor to desplay nos pressed
lcd.print(reference_no);
tempreferarray[x] = reference_no; //saving in array
reference_no = reference_no - reference_no; //so that reference_no is equal to the value before when loop is begun again
flag = false;
}
}
while(flag == true);
}
lcd.setCursor(4,0);
lcd.print("ref no");
delay(2000);
Serial.println(tempreferarray[3]); //display last no in array
tnx