I am trying to insert a variable from a keypad(Quantity) so I can find the amount of time to run the code( time=Quantity/800 ). Why is it not working? Thx a lot!
#include <Keypad.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 2); // set the LCD address to 0x27 for a 16 chars and 2 line display
int kdelay = 50;
int period = 0;
const byte ROWS = 4;
const byte COLS = 4;
char hexaKeys[COLS][ROWS] =
{
{ '1','4','7','*' },
{ '2','5','8','0' },
{ '3','6','9','#' },
{ 'A','B','C','D' }
};
byte rowPins[ROWS] = { 5, 4, 3, 2 };
byte colPins[COLS] = { 9, 8, 7, 6 };
Keypad kpd = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
int Quantity=0;
int time=0;
void setup() {
lcd.init();
lcd.backlight();
}
void loop() {
Quantity = GetNumber();
Serial.print("Quantity= ");
Serial.print(Quantity);
lcd.print(gramaj);
lcd.clear();
time=Quantity/800;
}
int GetNumber()
{
int num = 0;
char key = kpd.getKey();
while(key != '#')
{
switch (key)
{
case NO_KEY:
break;
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
lcd.print(key);
num = num * 10 + (key - '0');
break;
case '*':
num = 0;
lcd.clear();
break;
}
key = kpd.getKey();
}
return num;
}