Keypad

Hello..
I'm a beginner with Arduino programming and need some advice.plz Help!
What I need is How to send multiple different floating point or decimal values from keypad 4x4 to serial ?, then store them in a variable and put on LCD display. The variables are three, and for each one the user can enter values. My code looks somtehing like this (That’s work on the int value input but not on the decimal values input):

void loop()
{
v1 = GetNumber();
Serial.print("V1 = ");Serial.print(v1);Serial.println();
v2 = GetNumber();
Serial.print("V2 = ");Serial.print(v2);Serial.println();
v3 = GetNumber();
Serial.print("V3 = ");Serial.print(v3);Serial.println();

}

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':case '.':

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

case 'C':
num = 0;
//lcd.clear();
break;
}
key = kpd.getKey();
}
return num;
}

That looks like okey. Make it complete, compile and run.

I don’t know how to make that can you provide me some help about multiple decimal input ??

Int_Keypad.ino (1.43 KB)

Update Your initial post and use code tags for code, the symbol up to the left in this window. My Win10 Pc doesn't download Your file.

What is "multiple decimal input"?

//Excuse me sir … I have three variables are v1,v2,v3 and for each one I would to enter decimal value suppose that value v1=1.3;v2=1.5;v3=3.5; how to send that from keypad 4*4 then store var and put on LCD display.

#include <Keypad.h>
float v1 = 0;
float v2 = 0;
float v3 = 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};
byte colPins[COLS] = {17,16,15,14};   

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

void setup()
{
//lcd.init();                             
//lcd.commandWrite(0x0F);               
//lcd.clear();                             
Serial.begin(9600);                     
}

void loop()
{
v1 = GetNumber();
Serial.print("V1 = ");Serial.print(v1);Serial.println();
v2 = GetNumber();
Serial.print("V2 = ");Serial.print(v2);Serial.println();
v3 = GetNumber();
Serial.print("V3 = ");Serial.print(v3);Serial.println();

}

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':case '.':
      
         //lcd.print(key); 
         num = num * 10 + (key - '0');
         break;

      case 'C':
         num = 0;
         //lcd.clear();
         break;
   }

   key = kpd.getKey();
}

return num;
} 
[code][/#include <Keypad.h>
float v1 = 0;
float v2 = 0;
float v3 = 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};
byte colPins[COLS] = {17,16,15,14};   

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

void setup()
{
//lcd.init();                             
//lcd.commandWrite(0x0F);               
//lcd.clear();                             
Serial.begin(9600);                     
}

void loop()
{
 v1 = GetNumber();
Serial.print("V1 = ");Serial.print(v1);Serial.println();
 v2 = GetNumber();
Serial.print("V2 = ");Serial.print(v2);Serial.println();
 v3 = GetNumber();
Serial.print("V3 = ");Serial.print(v3);Serial.println();

}

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':case '.':
       
          //lcd.print(key); 
          num = num * 10 + (key - '0');
          break;

       case 'C':
          num = 0;
          //lcd.clear();
          break;
    }

    key = kpd.getKey();
 }

 return num;
}

[/code]

What Keypad are you using ?

1.3 might be 1*3

v1,v2,v3 would be ‘type’ float.

When * is detected the following digits will be the decimal portion.

I have no idea what ‘.’ - ‘0’ evaluates to.

Please remember to use code tags when posting code

Sir I wrote the code tags, it works when I enter two int values, but my problem is how to send 2 decimal values from keypad 4x4 ?, then store them in v1,v2 !?

Copy the text into the computer buffer: mark it and Ctrl+c. Then in Your post You click on the symbol “</>” up to the left. Then use Ctrl+v, and voaila.

Assign one key as decimal point. put it into the switch/case and work out how to handle the number keys being read.

You could maybe do it with a single function.
You pass the function references to an “int” and a “float”.
The return value of the function could indicate which is valid.

Or simply use a larger integer return type and return scaled integer values.

I hope for more clarification, as I said at the beginning my post (I'm a beginner with Arduino programming and I need some advice !!)

Start working through an Arduino learners kit. Those 30 experiments will make You learn and understand. Don't expect ready food popping up here.

:confused: Arduino is a beautiful world, but it needs beautiful people and professors who love giving. Unfortunately, there is no rated for that here, but your value is not acceptable.

Yes, Arduino, programming and electronics is really fun and fascinating. However You almost try to bring down the moon. You try to jump into a level faar more high than Your knowledge and experience can help You.

Why starting this proj at all? This kind of funny toys calls for knowledge You obviously don't have.

“ Unfortunately, there is no rated for that here, but your value is not acceptable. ”

Are you saying what we are thinking you are saying? ???

How many places after the decimal do you need?

What is the largest integer part do you need?

Do you need negative numbers?

Surely someone somewhere must have put a library together with something like inputIntegerFromKeypad() and inputFloatFromKeypad()?

I say that having looked before, and not finding one: I'm very surprised that functionality's not part of Keypad.h tbh.

Many OPs think that a "Library" makes every proj working. An elementary coarse in programming would solve the problem. Receiving the decimal point character switching into a mode reading chars, adding them using a divisor of first 10, then 100, then 1000, looks like elementary to me.

What is wrong with using sscanf()?

Railroader:
Many OPs think that a "Library" makes every proj working

It can certainly save a bit of time.

Railroader:
.... looks like elementary to me.

Trivial actually, and that's what I've done for my own use over the years.

But it's probably such a common requirement that someone somewhere who wrote their own functions might have said "hey, others can use this, let me ease the way and publish it". That's likely how many libraries come about, I'd wager.