About the Getnumber() library

Hello,
I'm just working based on a project which has two lcds and one touchpad to validate 3types of user data to store into it. But due to some reasons my GetNumber() is not working. I'm using a 4x4 matrix display for the input. if someone helps to sort this out it will be a great help to me.

Thanks in advance.

Welcome to the forum

You started a topic in the Uncategorised category of the forum when its description explicitly tells you not to

Your topic has been moved to a relevant category. Please be careful in future when deciding where to start new topics

It's unlikely that anyone can help without seeing your code.

Read the forum guidelines to see how to properly ask a question and some good information on making a good post. You will get faster and better help if you post more detail about your project, indicate a board used, and show all your code as requested by the forum guidelines.

#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
#include <max6675.h>
#include <LCD_I2C.h>

#define Relay_Pin 10

const int Start_Pin = 11;
int button_state = 0;

String v1;
String v2;
String v3;


const byte ROWS = 4;
const byte COLS = 4;

char keys[ROWS][COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};

byte rowPins[ROWS] = {2, 3, 4, 5}; // Connect to the row pins of the keypad
byte colPins[COLS] = {6, 7, 8, 9}; // Connect to the column pins of the keypad

Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);




// Set the LCD number to find
LiquidCrystal_I2C lcd2(0x26, 16, 2);
LiquidCrystal_I2C lcd1(0x27, 16, 2);

void setup()
{
  pinMode(Relay_Pin, OUTPUT);
  pinMode(Start_Pin, INPUT);
	// initialize the LCD
	lcd1.begin();
  lcd2.begin();
  
  Serial.begin(9600);
	// Turn on the blacklight and print a message.
	lcd1.backlight();
  lcd2.backlight();
  
}

void loop()
{
{
  v1 = getValue();
  v1.toInt();
}
  String getValue();
 {
  String num;
  char key = keypad.getKey();
  while(key != 'D') 
  {
    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':

      lcd1.print(key);
      num = num * 10 + (key - '0');
      break;

      case '#':
      num = 0;
      lcd1.clear();
      lcd2.clear();
      break;
    }
    key = keypad.getKey();
  }
  return num;
  }
  button_state= digitalRead(Start_Pin);
  if (button_state == HIGH);
  {
 digitalWrite(Relay_Pin, HIGH);
 delay(2000); 
}}```


Still it has not completed please check once

@connection
I insert your code to you
To do it correct you have to place a three apostrrofes on SEPARATE lines

After adding the code - please clarify your question.
I don't see anything about GetNumber() in your code.

They are not apostrophes they are back ticks, on a Mac keyboard this is next to the left hand shift key. On windows they can be under the Esc key at the top left.

Thank you
Unfortunately, my lexicon is a quite narrow.

sir basically I'm trying to write a PID temp control program. Where I have 2 lcds. In the first LCD I will show two temp sensors Set and present value. In another LCD another device Set and Present value will be shown. But to enter all 3 SET parameters I have a 4x4 Keypad. Now I'm trying to write the function when I will praise D it will set value for 1st one after praising # it will be free and will be ready to take for the second input.

For that I've called the string to do that and in place of GetNumber() using getValue(). But due to some reason it's not working. If u give any suggestion it will be great help to me.

Before talking about work - your code doesn't compile.
Please show a full error message using code tags.

It seems that you tried to define your getValue() function inside the loop().
It is incorrect - in the C language nested functions are not allowed.






















Z:\open source\Bin\nitinProjectkickoff\nitinProjectkickoff.ino: In function 'void loop()':

nitinProjectkickoff:60:8: error: 'getValue' was not declared in this scope

   v1 = getValue();

        ^~~~~~~~

nitinProjectkickoff:81:17: error: no match for 'operator*' (operand types are 'String' and 'int')

       num = num * 10 + (key - '0');

             ~~~~^~~~

nitinProjectkickoff:85:13: error: ambiguous overload for 'operator=' (operand types are 'String' and 'int')

       num = 0;

             ^

In file included from C:\Users\Kiran\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\cores\arduino/Arduino.h:232:0,

                 from sketch\nitinProjectkickoff.ino.cpp:1:

C:\Users\Kiran\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\cores\arduino/WString.h:86:11: note: candidate: String& String::operator=(const String&)

  String & operator = (const String &rhs);

           ^~~~~~~~

C:\Users\Kiran\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\cores\arduino/WString.h:87:11: note: candidate: String& String::operator=(const char*)

  String & operator = (const char *cstr);

           ^~~~~~~~

C:\Users\Kiran\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\cores\arduino/WString.h:88:11: note: candidate: String& String::operator=(const __FlashStringHelper*)

  String & operator = (const __FlashStringHelper *str);

           ^~~~~~~~

C:\Users\Kiran\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\cores\arduino/WString.h:90:11: note: candidate: String& String::operator=(String&&)

  String & operator = (String &&rval);

           ^~~~~~~~

C:\Users\Kiran\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\cores\arduino/WString.h:91:11: note: candidate: String& String::operator=(StringSumHelper&&)

  String & operator = (StringSumHelper &&rval);

           ^~~~~~~~

Z:\open source\Bin\nitinProjectkickoff\nitinProjectkickoff.ino:92:10: warning: return-statement with a value, in function returning 'void' [-fpermissive]

   return num;

          ^~~

exit status 1

'getValue' was not declared in this scope



This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.```

sir basically I'm trying to write a PID temp control program. Where I have 2 lcds. In the first LCD I will show two temp sensors Set and present value. In another LCD another device Set and Present value will be shown. But to enter all 3 SET parameters I have a 4x4 Keypad. Now I'm trying to write the function when I will praise D it will set value for 1st one after praising # it will be free and will be ready to take for the second input.

For that I've called the string to do that and in place of GetNumber() using getValue(). But due to some reason it's not working. If u give any suggestion it will be great help to me.


#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
#include <max6675.h>
#include <LCD_I2C.h>

#define Relay_Pin 10

const int Start_Pin = 11;
int button_state = 0;

const byte ROWS = 4;
const byte COLS = 4;

char keys[ROWS][COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};

byte rowPins[ROWS] = {2, 3, 4, 5}; // Connect to the row pins of the keypad
byte colPins[COLS] = {6, 7, 8, 9}; // Connect to the column pins of the keypad

Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);


// Set the LCD number to find
LiquidCrystal_I2C lcd2(0x26, 16, 2);
LiquidCrystal_I2C lcd1(0x27, 16, 2);


int v1;
int v2;
int v3;
int getValue() {
  while (!Serial.available()) {
  }
  
  // Read the integer value from serial input
  int value = Serial.parseInt();
  
  // Clear the serial buffer
  while (Serial.available()) {
    Serial.read();
  }
  
  return value;
}

void setup()
{
  pinMode(Relay_Pin, OUTPUT);
  pinMode(Start_Pin, INPUT);
	// initialize the LCD
	lcd1.begin();
  lcd2.begin();
  
  Serial.begin(9600);
	// Turn on the blacklight and print a message.
	lcd1.backlight();
  lcd2.backlight();
  
}

void loop()
{
  {
  v1 = getValue();
  v2 = getValue();
  v3 = getValue();
  }
{
  v1 = getValue();
}
  int getValue();
 {
  int num;
  char key = keypad.getKey();
  while(key != 'D') 
  {
    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':

      lcd1.print(key);
      num = num * 10 + (key - '0');
      break;

      case '#':
      num = 0;
      lcd1.clear();
      lcd2.clear();
      break;
    }
    key = keypad.getKey();
  }
  return num;
  }
{
  v2 = getValue();
}
  int getValue();
 {
  int num;
  char key = keypad.getKey();
  while(key != 'D') 
  {
    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':

      lcd1.print(key);
      num = num * 10 + (key - '0');
      break;

      case '#':
      num = 0;
      lcd1.clear();
      lcd2.clear();
      break;
    }
    key = keypad.getKey();
  }
  return num;
  }
  {
  v3 = getValue();
}
  int getValue();
 {
  int num;
  char key = keypad.getKey();
  while(key != 'D') 
  {
    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':

      lcd1.print(key);
      num = num * 10 + (key - '0');
      break;

      case '#':
      num = 0;
      lcd1.clear();
      lcd2.clear();
      break;
    }
    key = keypad.getKey();
  }
  return num;
  }
{
  button_state= digitalRead(Start_Pin);
  if (button_state == HIGH);
  {
 digitalWrite(Relay_Pin, HIGH);
 delay(2000); 
}}}```

I don't think the code you posted will even compile. You will get errors because you are defining a function within a function and maybe others.

Please post the code you have successfully uploaded to the Arduino but does not work as desired. But before you post it, please use Auto-Format. Also please remove any unnecessary {} such as these:

  {
  v1 = getValue();
  v2 = getValue();
  v3 = getValue();
  }

sir I've updated this pls check once

#include <LiquidCrystal_I2C.h>
#include <Keypad.h>

#define Relay_Pin 10
const int Start_Pin = 11;
int button_state = 0;

const byte ROWS = 4;
const byte COLS = 4;

char keys[ROWS][COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};

byte rowPins[ROWS] = {2, 3, 4, 5}; // Connect to the row pins of the keypad
byte colPins[COLS] = {6, 7, 8, 9}; // Connect to the column pins of the keypad

Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);

LiquidCrystal_I2C lcd1(0x27, 16, 2); // LCD 1
LiquidCrystal_I2C lcd2(0x26, 16, 2); // LCD 2

int v1;
int v2;
int v3;
int getValue() {
  int num = 0;
  char key = keypad.getKey();
  while (key != 'D') {
    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':
        lcd1.print(key);
        num = num * 10 + (key - '0');
        break;

      case '#':
        num = 0;
        lcd1.clear();
        lcd2.clear();
        break;
    }
    key = keypad.getKey();
  }
  return num;
}

void setup() {
  pinMode(Relay_Pin, OUTPUT);
  pinMode(Start_Pin, INPUT_PULLUP); // Assuming Start_Pin is pulled up internally
  
  // Initialize the LCDs
  lcd1.begin();
  lcd2.begin();
  
  Serial.begin(9600);
  
  lcd1.backlight();
  lcd2.backlight();
}

void loop() {
  v1 = getValue();
  v2 = getValue();
  v3 = getValue();
  
  button_state = digitalRead(Start_Pin);
  if (button_state == LOW) { // Check if the button is pressed (assuming it's active low)
    digitalWrite(Relay_Pin, HIGH);
    delay(2000); // Adjust delay as needed
  }
}```

You can make this shorter:

case '0' .. '9':

I don't think this will work as you wanted.

The calls to getValue() will each wait until a value has been entered. So pressing the button will not be detected, except in the instant after the final value has been entered. Otherwise the button press will be missed.

I have merged your cross-posts @connection.

Cross-posting is against the Arduino forum rules. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend a lot of time investigating and writing a detailed answer on one topic, without knowing that someone else already did the same in the other topic.

Repeated cross-posting can result in a suspension from the forum.

In the future, please only create one topic for each distinct subject matter. This is basic forum etiquette, as explained in the "How to get the best out of this forum" guide. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

thnx for ur help I'm trying to fix it