Hi there,
I need to read several inputs from a keypad (Membrane 3x4 Matrix Keypad + extras [3x4] : ID 419 : $3.95 : Adafruit Industries, Unique & fun DIY electronics and kits)
I wait until a user as pressed a key to store the values. I would like to recycle a temporary variable, however it seems that it keeps memory of the previous usage. Is there a way to clear that?
I show you what I mean, look at this code
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
void read_values() {
lcd.setCursor(0, 0);
lcd.print("Insert only ");
lcd.setCursor(0, 1);
lcd.print("numeric values");
delay(2000);
lcd.clear();
// Select number of cycle
lcd.setCursor(0, 0);
lcd.print("Number of cycles");
lcd.setCursor(0, 1);
lcd.print("2 digits: ");
int key = keypad.getKey();
int key2 = keypad.getKey();
while( key == NO_KEY )
{ key = keypad.getKey() ; }
key = key -48; // Subtract 48 to make the conversion from char to int
lcd.print(key);
while( key2 == NO_KEY )
{ key2 = keypad.getKey(); }
key2 = key2 -48;
lcd.print(key2);
NUM_CYCLES = key*10+key2;
delay(3000);
lcd.clear();
// Select DENATURE_TEMP
lcd.setCursor(0, 0);
lcd.print("Denature temp. ");
lcd.setCursor(0, 1);
lcd.print("in celcius: ");
while( key == NO_KEY )
{ key = keypad.getKey();
lcd.print("ok"); }
key = key -48;
lcd.print(key);
while( key2 == NO_KEY )
{ key2 = keypad.getKey();
}
key2 = key2 -48;
lcd.print(key2);
DENATURE_TEMP = key*10+key2;
delay(3000);
lcd.clear()
}
Until I am filling the first variable "NUM_CYCLES", everything is fine.
When I want to fill DENATURE_TEMP, key2 is read properly but key is automatically using the old value inserted before.
A solution could be to use another variable, but there should be a way to reset this variable so that is ==NO_KEY
and doing key = NO_KEY, doesn't work