Below is the complete code.The problem is it is working on serial,but implementing on lcd it only fetching 1st value only not going further.
Regards
JR
#include <LiquidCrystal.h>
#include "Keypad.h"
#include "Wire.h" // for I2C LCD
// Initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
// keypad type definition
const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char customKey;
int total = 0;
char keys[ROWS][COLS] =
{ {'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {2, 3, 11, 12}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {A2, A3, A4, A5}; // connect to the column pinouts of the keypad
int count = 0;
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
//===========================================================================
void setup() {
//Set the characters and column numbers.
//lcd.init();
Serial.begin(9600);
lcd.begin(16, 2);
// set up the switch pin as an input
lcd.clear();
}
void loop() {
//customKey = myKeypad.getKey();
char key = keypad.getKey();
switch(customKey)
{
case 'C':
guru();
break;
}
if (key != NO_KEY)
{
lcd.print(key);
count++;
if (count == 17)
{
lcd.clear();
count = 0;
}
}
}
int FindItemData(int whichOne, char *item, int *price)
{
static char *Stt[100] = {"Rice", "Oil", "Masal", "HCare", "HairC", "Baby", "Pickle", "Oral Care", "Dry Fruits", "Noodles", "Midha"};
static int prices[100] = {0, 52, 70, 15, 62, 75, 175, 58, 44, 17, 30, 35};
int flag = 0;
if (whichOne < (sizeof(Stt) / sizeof(Stt[0]))) {
strcpy(item, Stt[whichOne]);
*price = prices[whichOne];
flag = 1;
} else {
*item = NULL;
*price = -1;
flag = 0;
}
return flag;
}
void guru()
{
char key = keypad.getKey();
char buffer[10];
int index, val, price, ret;
if (count>key) {
// digitalRead;
//count++;
//index = Serial.readBytesUntil('\n', buffer, 9); // Look for newline or max of 9 chars
buffer[index] = '\0'; // It's now a string
val = atoi(buffer); // Now it's an int
ret = FindItemData(val, buffer, &price);
if (ret) {
Serial.print(buffer);
Serial.print(" ");
Serial.println(price);
delay(200);
//lcd.clear();
}
}
}