Hi. I am working a project which can organize your food in the kitchen. Every time you get some food then You have to key in the expiry date of it every time you get some food and when the expiry date comes it will notify you.
But I'm having a problem that after I key in the numbers and press the hashtag button(enter button), the value it shows is just 'K', which I have no idea what went wrong. This problem doesn't happen when I serial print the 'product' variable and only happens when I try to serial print the food array.
Here's the code:
#include <LiquidCrystal.h>
#include <Keypad.h>
//initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12,11,5,4,3,2);
//4x4 Matrix key pad
const byte ROWS = 4; // Four rows
const byte COLS = 4; // Four columns
int letter = 0; //cursor position
int productn = 0; //product number
char product[15]; //value keyed in with keypad
char food[100]; //food in kitchen
// Define the Keymap
char keys[ROWS][COLS] =
{
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to Arduino pins.
byte rowPins[ROWS] = { 14, 15, 16, 17 };
// Connect keypad COL0, COL1, COL2 and COL3 to Arduino pins.
byte colPins[COLS] = { 18, 19, 20, 21 };
// Create the Keypad
Keypad kpd = Keypad( makeKeymap(keys), rowPins,
colPins, ROWS, COLS );
void setup()
{
Serial.begin(9600);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
}
void loop()
{
char key
= kpd.getKey();
if(key) {
if(key == '*'){
letter = 0;
lcd.clear();
memset(product, 0, sizeof(product));
}
if(key == '#'){
letter = 0;
lcd.clear();
food[productn] = product;
Serial.println(food[productn]);
memset(product, 0, sizeof(product));
productn++;
}
if(key != '*' && key != '#') {
product[letter] = key;
lcd.setCursor(letter, 0);
//Print the detected key
lcd.print(key);
letter++;
}
}
}
I also attached the value shown on the serial monitor.
