Need some help sending commands through Serial without a keyboard

I'm looking into how to turn the numbers & decimals I type on the keypad into two seperate floating numbers (which will be named 'num1' and 'num2')

I've researched into the keypad library, but I wasn't able to get anything to do this using the getKey command - still working on this.

Also, Thank you again for your time! I seriously appreciate all of the direction you've given so far

You write a function [like the one I provided] and then call it the first time to retrieve num1 and then call it a second time to retrieve num2.

I'm beginning to think you should step back and take some time to learn C/C++ and basic programming before tackling this project. Maybe explore some of the examples that come with the IDE (File->Examples->...) and really understand how they work.

I can't thank you enough blh64! You as well as others have been awesome at guiding me with this, and I seriously appreciate your time and patience! Let's get this code on par!

I've been going through the different Arduino examples/libraries (haven't gotten to all of them yet), but most of them didn't lead me too far with my own project - I'll take another look, particulary at Keypad, and Adafruit_LiquidCrystal

I'm trying to overlook the examples that use Serial or Stream

I do understand that I need a function to call 'num1' and 'num2' - I'll rework this so that it is two individual functions though. After you reworded it, you've given me another idea for where to put the 'num1' as well - but I guess I'm still missing the part of the code that calls for multi-digit numbers, as well as decimals.

I'm going to work on getting that fixed^^, and I'll post back with the results.

Yep, I'm definitely very lost on how to do this.

Sorry if your explanations have covered this, but I can't figure out how to make this code do what I'd like it to do. Step 1 right now is to figure out how to read a number, with a decimal to four places.

The function you provided prints number, and it prints a decimal, but I still don't see a way to make those the same number.

No matter how I rework the function you provided, the last digit that I type will be the value for num 1.

If I type 2.4002, then the value for num1 is 2.0000

If I type 2.4576, then the value for num1 is 6.0000

I'm still working on getting a lot of bugs out of this version - If anyone has any input on how to improve this, I'm all ears.

Also... Would it be better to start a whole new post about this, seeing how the original title is no longer what I'm trying to do?

If I type 2.4002, then the value for num1 is 2.0000

If I type 2.4576, then the value for num1 is 6.0000

I see a pattern.
A third example could possibly confirm.

TheMemberFormerlyKnownAsAWOL:
I see a pattern.
A third example could possibly confirm.

For your trollocity

4.2487

The number... will be 7.0000

hail to the gods |m|

lol

Jokes aside..

I realize that the answer has probably been written, but I'm still trying to find that path to get there, and understand how I got there, if that makes sense.

Finally working on creating a seperate char for each digit that will be entered, as suggested by blh64 in their original post

blh64 -

Regarding the function you've provided - What is this line for?

input[idx] = '\0';

Thanks! Hoping I haven't scared anyone away with my basic questions!

I'm trying to go back to the beginning here, and rebuild so that I understand completely what is happening in the code - I noticed that I had to change some things from the original function in order to get everything to display correctly.

Not that it was necessary, but I also changed the name of 'key' back to 'customKey'

Here is how it reads now (from the 'loop' function):

const byte nChars = 15;
  char input[nChars];
  byte idx = 0;
  char customKey = customKeypad.getKey();

if (customKey) {
    switch (customKey) { 
      case '0' ... '9':
      lcd.print(customKey);

instead of

const byte nChars = 15;
    char input[nChars];
    byte idx = 0;
    int key = 0;

    while ( key != '#' ) {
      key = customKeypad.getKey();
      switch (key) {
        case '0' ... '9':

Before doing this, the LCD would just display lines

Delta_G:
Then do something to make 12 and 3 into 123. Etc etc.

Thanks for the reply.
That's actually exactly what I've been asking for help with.

'do something'... Do what?

I've looked at a lot of examples, but I'm not finding anything 'that do this'

I'm going to start a new topic for this project anyway, as the original title is no longer relevant to what I'm trying to accomplish.

Here's a link - please follow on this new thread!

https://forum.arduino.cc/index.php?topic=639684.0

Thanks everybody!

zrockafellow:
blh64 -

Regarding the function you've provided - What is this line for?

input[idx] = '\0';

Thanks! Hoping I haven't scared anyone away with my basic questions!

a string (lower case 's') in C/C++ consists of an array or chars followed by the char 0 to terminate the string. the value '0' is the ascii value of 48 but the ascii value of '\0' is 0 which is the null (or nil) char that terminates the string to functions like atof() know when to stop processing the input.

Here's a complete example of reading in floating point numbers. It uses Serial to display the results on your Serial Monitor and it also does not include the lcd so you will have to add that in.

/* @file CustomKeypad.pde
|| @version 1.0
|| @author Alexander Brevig
|| @contact alexanderbrevig@gmail.com
||
|| @description
|| | Demonstrates changing the keypad size and key values.
|| #
*/
#include <Keypad.h>

const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys[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 pinouts of the keypad
byte colPins[COLS] = {6,7,8,9}; //connect to the column pinouts of the keypad

//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); 

void setup(){
  Serial.begin(9600);
  Serial.println( "ready for input on keypad" );
}
  
void loop(){
  float num1 = readNumber();
  Serial.print( "num1=" );
  Serial.println( num1, 2 );
  float num2 = readNumber();
  Serial.print( "num2=" );
  Serial.println( num2, 2 );
}




float readNumber() {
  const byte nChars = 15;
  char input[nChars];
  byte idx = 0;
  int key = 0;

  while( key != ',' ) {
    key = customKeypad.getKey();
    switch (key) {
      case '0' ... '9':
      case '.':
        if ( idx < nChars-1 ) {
          input[idx++] = key;
        }
        Serial.print( "pressed " );
        Serial.println( (char) key );
        break;

      case ',':
        input[idx] = '\0';
        Serial.print( "pressed " );
        Serial.println( (char) key );
    }
  }
  Serial.print( "input=" );
  Serial.println(input);
  return atof(input);
}