Store 2 values with numpad

Hi!
I'm not soo good at programming so this might be an easy fix but i can't think of one.
I'm trying to store 2 values in different variables but I'm having trouble doing it, I've already manage to store 1 of them (lmax).

#include <Keypad.h>
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};

LiquidCrystal_I2C lcd(0x27,20,4);  // set the LCD address to 0x27 for a 16 chars and 2 line display

byte rowPins[ROWS] = {2, 10, 11, 12}; //connect to the row pinouts of the kpd
byte colPins[COLS] = {13, 7, 8}; //connect to the column pinouts of the kpd

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
unsigned long loopCount;
unsigned long startTime;
String msg;
int lmax = 0;
int lmin = 0;

int getKeypadIntegerMulti()
{
  int value = 0;                                // the number accumulator
  int keyvalue;                                     // the key pressed at current moment
  int isnum;
  do
  {
    keyvalue = keypad.getKey();                          // input the key
    isnum = (keyvalue >= '0' && keyvalue <= '9');         // É um digito?
    if (isnum)
    {
      Serial.print(keyvalue - '0');
      value = value * 10 + keyvalue - '0';    // accumulate the input number
    }
    
  } while (isnum || !keyvalue);// until not a digit or while no key pressed
   
  return value;
  
}//getKeypadInteger
void setup() {
  lmax = lmax + getKeypadIntegerMulti();
  lcd.init();                      // initialize the lcd 
  lcd.init();
  lcd.backlight();
  lcd.print("Limite Max.:");
  lcd.print(lmax);
  }

void loop() {

}

Here's the code, I'd appreciate if you guys could help me!

Not sure why you add something to lmax; just assigning should be sufficient.

Maybe I'm missing what you're stuck with but how about

void setup() {
  lmax = getKeypadIntegerMulti();
  lmin = getKeypadIntegerMulti();
  ...
  ...
}

I'm doing a project using a DHT11 to make a weather station, the objective is to make it turn an AC with cold air in case the DHT11 temperature gets higher than max number typed by the user or to turn the AC hot air in case the temperature gets lower than typed.
I'l have a relay module to simulate the AC but that's why i need to store two different values.
And i was adding "getKeypadIntegerMulti()" to lmax because for some reason when I tried to just assign the value showed on the lcd was 0.

how does the user know when to enter number? is there a prompt displayed on the LCD? is there a button the user needs to press to enter a configuration mode in which these numbers are entered? what does the LCD display when not in a configuration mode?

when entering a single digit, should it be displayed on the LCD, rather than waiting for a complete number to be entered?

I had a "lcd.print" before asking for a number but for some reason it didn't work.
When not in configuration mode the lcd displays the temperature and humidity of the room and since we're talking about temperature reading only one digit wouldn't work since most of the time two would be needed.

i'm suggesting that when entering a #, the display is updated after each digit. the user enters '7', "7" is displayed, then the user enters '2' and "72" is displayed.

i think you need to think out the user interface

Ho I get what you're saying, it would look way better indeed.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.